Offline Version on Ubuntu for MySQL

Modified on Sat, 23 Jul, 2016 at 5:11 PM

MySQL is a popular database management system used for IVMS server applications. This guide will introduce how to install, configure and manage MySQL on a running Ubuntu 14.04 LTS (Trusty Tahr) using offline binary packages.

· Check the system’s hostname

To check your hostname run:
            #hostname
            #hostname –f

The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).

Before installation, identification of installed OS is required.

 Check output of following command:

 

 #cat /etc/*-release

 

Typical Output:

 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"
NAME="Ubuntu"
VERSION="14.04, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" 
 
For Checking architecture, use following command:

 # uname –m

 

Typical Output:

X86_64

The above output ensures that installed OS is 64 Bit.


Install Binary Packages from Delivered CD/DVD Media

· Open Terminal

#cd <Prerequsite Server\MYSQL-Ubuntu-14.04>/Binary-deb

 

#dpkg -i libnet-daemon-perl_0.48-1_all.deb
            #dpkg -i libplrpc-perl_0.2020-2_all.deb
            #dpkg -i libdbi-perl_1.630-1_amd64.deb
            #dpkg -i mysql-common_5.5.38-0ubuntu0.14.04.1_all.deb
            #dpkg -i libmysqlclient18_5.5.38-0ubuntu0.14.04.1_amd64.deb
            #dpkg -i libdbd-mysql-perl_4.025-1_amd64.deb
            #dpkg -i libterm-readkey-perl_2.31-1_amd64.deb
            #dpkg -i mysql-client*.deb
            #dpkg -i libaio1_0.3.109-4_amd64.deb
            #dpkg -i mysql-server*.deb
            #dpkg -i libhtml-template-perl_2.95-1_all.deb
            #dpkg -i libclone-perl_0.36-1_amd64.deb
            #dpkg -i heirloom-mailx_12.5-2_amd64.deb
            #dpkg -i postfix_2.11.0-1_amd64.deb
            #dpkg -i bsd-mailx_8.1.2-0.20131005cvs-1_amd64.deb
            #dpkg -i libipc-sharelite-perl_0.17-3build1_amd64.deb
            #dpkg -i libipc-sharedcache-perl_1.3-8_all.deb
            #dpkg -i libmldbm-perl_2.05-1_all.deb
            #dpkg -i libparams-util-perl_1.07-1build1_amd64.deb
            #dpkg -i libsql-statement-perl_1.405-1_all.deb
            #dpkg -i mailutils-common_2.99.98-1.1_all.deb
            #dpkg -i libkyotocabinet16_1.2.76-4_amd64.deb
            #dpkg -i libntlm0_1.4-1_amd64.deb
            #dpkg -i libgsasl7_1.8.0-2ubuntu2_amd64.deb
            #dpkg -i libmailutils4_2.99.98-1.1_amd64.deb
            #dpkg -i mailutils_2.99.98-1.1_amd64.deb
            #dpkg -i libcairo-perl_1.104-1_amd64.deb
            #dpkg -i libglib-perl_1.304-1_amd64.deb
            #dpkg -i libpango-perl_1.224-2_amd64.deb
            #dpkg -i libgtk2-perl_1.249-2_amd64.deb
            #dpkg -i tinyca_0.7.5-5_all.deb

During execution of command “dpkg -i mysql-server*.deb” , you will be asked to provide the mysql admin password as shown below. Choose a strong password and keep it in a safe place for future reference.

After reboot and auto-login open terminal ( ALT +CTRL +T or from menu)


 To check whether MySQL is installed correctly, run the following command

            netstat –tap | grep mysql

Typical output : tcp        0          0          localhost:mysql *.*         LISTEN 2173/mysql

Where 2173 is the process id. It will differ in your case.

This will confirm MySQL Server is running and operational.

· Configuration of MySQL Server:

The standard tool for interacting with MySQL is the mysql client which installs with the mysql-server package. The MySQL client is accessed through a terminal.

After completion of the above steps, please configure the MySQL server as follows:

To log in to MySQL as the root user: 

# mysql –u root –p

When prompted, enter the root password you assigned during installation.

You’ll then be presented with the MySQL monitor prompt:


To generate a list of commands for the MySQL prompt, enter \h. You’ll then see:



To display which accounts exist in the mysql.user table and check whether their passwords are empty, use the following statement:

mysql> SELECT User, Host, Password FROM mysql.user;

 
Sample output as follows: 
+------+--------------------+----------+
| User | Host               | Password |
+------+--------------------+----------+
| root | localhost          |          |
| root | myhost.example.com |          |
| root | 127.0.0.1          |          |
|      | localhost          |          |
|      | myhost.example.com |          |
+------+--------------------+----------+

mysql>\q

Assigning root Account Passwords

· Open Terminal

 
#mysql -u root -p

When prompted, enter the root password you assigned during installation step.

mysql> UPDATE mysql.user SET Password = PASSWORD('root') WHERE User = 'root';
mysql> FLUSH PRIVILEGES;

The FLUSH statement causes the server to reread the grant tables. Without it, the password change remains unnoticed by the server until you restart it.

Logout from database :

mysql> \q
 

To allow connection from remote host to newly created database, username do the following in server side.

 

· Open Terminal

#mysql -u root -p

When prompted, enter the root password you assigned during installation.

 
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';

mysql>FLUSH PRIVILEGES;

Secure MySQL Server

Now that you have setup MySQL on Ubuntu Server, let us secure it. Securing your MySQL database server is highly recommended and it is very easy to do. Just run the following command and follow through the 6 steps. 

                               #sudo mysql_secure_installation

As shown in the picture below, first you will be asked to enter the current root password to continue. Then you will have the option to change the root password. You can say “n” if you don’t want to change it. Then say “Y” to “Remove Anonymous Users”, “n” to “Disallow root login remote”, and “n” to “Remove test database and access to it”. And finally, answer “Y” to reload the new privileges.

This is the end of configuration section. 


MySQL is one of the most used database worldwide. To manage MySQL database there are lot of open source GUI tools are available. Some of the popular GUI based tools is MySQL workbench, phpMyAdmin etc.

 

MySQL Workbench is a GUI based visual tool. Workbench is widely used by developers,  DBAs for data modeling, SQL development, and comprehensive administration tools for server configuration, user administration, backup, and much more. This tool is available for Windows, Linux and Mac OS operating system.

In this tutorial we will show how to install MySQL workbench on Ubuntu 14.04. 

 

Install MySQL Workbench

· Open Terminal

                    #cd <Prerequsite_ Server\MYSQL-Ubuntu-14.04>/MySQLWB
                         #dpkg    -i     *.deb
It will install mysql-workbench and dependent packages in your system.

Launch MySQL Workbench (from your installed programs, and choose Workbench) 
Following window will appear:

Restore your database from a previous backup

  • Enter your database password when prompted.

NOTE: If you select Save password in vault MySQL Workbench will not ask you to enter your password again. You should never use this option on a public or shared computer.

  • Click Data Import / Restore under Management section


Select .sql file which will be different depending upon your application category(Pro VMS, ANPR, RLVD etc.)

As an example:
Application Name
Schema file
IVMS Pro
ivms_30.sql

Click Start Import and enter the database password if prompted. This process may take several minutes depending on the size of your database backup.


Troubleshooting :

·  Change the MySQL Root Password

This method exposes the password to the command-line history, these commands should be run as root.

1. Login through mysql command line tool:

# mysql –uroot –poldpassword

2. Run this command:

mysql>SET PASSWORD FOR root@'localhost' = PASSWORD('newpassword');

or

mysql>SET PASSWORD = PASSWORD('newpassword');

 

·  Reset the MySQL Root Password  [ Procedure 1 ]

               If you forget your root MySQL password, it can be reset.
               1. Stop the current MySQL server instance.
                              #sudo  service  mysql  stop
                                              Or
                               #sudo /etc/init.d/mysql stop

  2.        Start the mysqld configuration with below command: 

#sudo mysqld --skip-grant-tables &

  3. Login to MySQL as root 

#mysql -u root mysql
                After successful  execution , mysql prompt  will appear                     
mysql>
4.   Replace YOURNEWPASSWORD with your new password
               mysql>UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;

·  Reset the MySQL Root Password  [ Procedure 2 ]

               Step 1: Stop MySQL Service.
#sudo stop mysql
               Step 2: Kill all running mysqld.
#sudo killall -9 mysqld
               Step 3: Starting mysqld in Safe mode.
#sudo mysqld_safe --skip-grant-tables --skip-networking &
               Step 4: Start mysql client
#mysql -u root
               Step 5: After successful login, please execute this command to change any password. 
mysql>FLUSH PRIVILEGES;
               Step 6: You can update mysql root password.
mysql>UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
Step 7: Please execute this command.
mysql>FLUSH PRIVILEGES;

·  Database ErrorHost “domain.com' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'

               Sometimes, user can see above log messages during debugging. To resolve this unblock issue, do the below exercise:
               Linux:
                               # mysql -u root -p -e 'flush hosts'
     Windows:
                               mysql> SET GLOBAL max_connect_errors=10000;

 

How to uninstall mysql completely in ubuntu [ optional ]

1. Open terminal

2. Execute the following commands sequentially

        #apt-get remove - - purge mysql-server mysql-client mysql-common

             #apt-get autoremove

             #apt-get autoclean

How to move the mysql data directory in ubuntu [ Optional ]

  • Open the terminal
  • Stop MySQL with the command
    /etc/init.d/mysql stop

  • Copy the existing data directory (which is located in /var/lib/mysql) using the command
    cp -R -p /var/lib/mysql /opt/new_datadir

  • All you need are the data files. Delete the others with the command
    rm /opt/new_datadir
    (You will get a message about not being able to delete some directories, but do not care about them)
  • Edit the MySQL configuration file with the command
    nano /etc/mysql/my.cnf

  • Find the entry for datadir, change the path to the new data directory.
  • But there is a trick involved here. Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile for MySQL, you'll never be able to restart MySQL with the new datadir location.
  • In the terminal, enter the command
    nano /etc/apparmor.d/usr.sbin.mysqld

  • Copy the lines beginning with /var/lib/mysql
  • Comment out the originals with hash marks (#), and paste the lines below the originals.
  • Now change /var/lib/mysql in the two new lines with /opt/new_datadir.
  • Save and close the file.
  • Restart the AppArmor profiles with the command
    /etc/init.d/apparmor restart
  • Restart MySQL with the command
    /etc/init.d/mysql restart
  • MySQL should now start without any errors and your data will be stored in the new location.

    Backup Database in MySQL Server

     

    Backups are important with any kind of data, and this is especially relevant when talking about databases. MySQL can be backed up in a few different ways that we will discuss one of the popular method where we will use utility program  “automysqlbackup” that is available in the ubuntu repositories.

     

    This utility can be scheduled to automatically perform backup at regular intervals

     

    NOTE : Install the auto mysql backup package in the database server machine itself.


    Below steps will explain the procedure to configure step by step

     

    Step 1: Create  the directoryautomysqlbackup” under /etc

    #mkdir –p /etc/automysqlbackup

     

    Step 2: Copy configuration files to the proper destination directory
                 #cp Prerequisite Server/automysqlbackup/automysqlbackup.conf \
                 /etc/automysqlbackup/myserver.conf
                 #cp Prerequisite Server/automysqlbackup/automysqlbackup /usr/local/bin

     

    Step 3: Set executable permission to the required file

                 #chmod a+x  /usr/local/bin/automysqlbackup

     

    Step 4: Edit the configuration file with proper database name, database username , database password, backup directory location, port etc.
                 #gedit /etc/automysqlbackup/myserver.conf

     

    Edit the below few lines to meet your requirement

     

    CONFIG_mysql_dump_username='root' CONFIG_mysql_dump_password='root' CONFIG_backup_dir='/opt/databasebackup'

    CONFIG_db_names=('ivms_30')   # might be different in your  installation

    CONFIG_mysql_dump_port=3306

     

    Step 5: Create  a folder  /opt/database-backup . This is the backup file location . We recommend to set this in NAS.
                 #mkdir /opt/database-backup

    For NAS, the above command will be like this
                  #mkdir –p /mnt/nas1/DB-Backup [ Assuming NAS path : /mnt/nas1/DB-Backup ]

     

     

    Step 6: Run the below command once from command line for the first time.
                 #/usr/local/bin/automysqlbackup /etc/automysqlbackup/myserver.conf

     

    This will create all necessary meaningful folders/subfolders and files

    Search this directory “/opt/database-backup” to see the structure of the backup folders/files.

     

    Step 7: Now to run this script periodically you have to add this in CRONTAB.

     

    (i) Open  Terminal

    (ii) Open crontab
         #
    crontab –e
     

    [ It will ask what  editor should you use (First time) , Please choose   nano  editorIts easiest] 

    It will open  a window.

     

     Add  the following entry :
      # m h  dom mon dow  command

    30 5 * * * /usr/local/bin/automysqlbackup  /etc/automysqlbackup/myserver.conf

     

    This backup command execute  everyday at 5:30 morning

     

    If you look into the daily directory, you can see a subdirectory for each database, inside of which is a gzipped sql dump. Example  of such a file is “daily_centraldb_2015-12-01_05h30m_Tuesday.sql.gz “.

     

    NOTE : You can choose different schedule in CRON settings. To explore, CRONTAB read the manual by executing command
                                   #man crontab



    Restore Database in MySQL Server

    Restoration of database is equally important . Here is the explanation of restoration process with Snapshots.

    We are taking example of the gzipped schema from the previous page.

    Step 1: GUnzip the zipped sql file

                #gunzip  daily_centraldb_2015-12-01_05h30m_Tuesday.sql.gz


    Below sql file will be available in the same directory ( Eg: /root ]

                “ daily_centraldb_2015-12-01_05h30m_Tuesday.sql



    Step 2: Open Mysql Workbench:  

    Connect MySQL service . During this operation, root password is required.

    Click on Data Import /Restore


    Browse the unzipped .sql file from explorer.


    In this process you have to create database name . ( For example, the database name is “centraldb”).

    The name will be different for various product. ( Ex: for ivms rich version database name: ivms_20)

     

    Create a new database by clicking button “new” as marked in the below screen.

    After creating new database name, select the database from drop down menu. Then Click on “Start Import


    After successful importing, below screen will appear.

     

    Database and tables will be populated.

    Check table data .

     

    Crosscheck database name, username and password with the package which you want to run.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article