Skip to content

MySQL 5.1 Installation on Linux

April 24, 2010

MySQL installation on linux is very easy and only few minutes game. However, it has few little complications if you haven’t done it before. In this post i will explain how to install the MySQL on a linux box for a production use. To make mysql stable for production use you have to take care of few extra steps as mentioned in the post.

Most linux distribution comes with MySQL version of 5.0.x. If you want to install MySQL 5.1 you would first have to uninstall the old version.

Uninstall MySQL 5.0

First get the list of intalled mysql packages with the following command:

rpm -qa | grep -i mysql

or

rpm -qa | grep -i MySQL

It will show you all the installed modules. Now uninstall them one by one using:

rpm -e mysql

This could give you error because of dependencies. If you got error than use the following command to remove mysql without those dependencies:

rpm -e mysql –nodeps

Download MySQL 5.1 binaries

Now you have successfully uninstalled mysql. Download the new version (in our case 5.1) you want to install from http://dev.mysql.com/downloads/mysql/

You need to download the following modules:

  • MySQL server
  • MySQL devel
  • MySQL shared
  • MySQL client

You can use wget command to download these files.

Installing MySQL 5.1

Now install them one by one:

rpm -ivh MySQL-server-5.1.45-1.glibc23.x86_64.rpm
rpm -ivh MySQL-devel-5.1.45-1.glibc23.x86_64.rpm
rpm -ivh MySQL-shared-5.1.45-1.glibc23.x86_64.rpm
rpm -ivh MySQL-client-5.1.45-1.glibc23.x86_64.rpm

Now you have installed all the modules of MySQL. Test the service status:

service mysql status

MySQL running (9993)                                       [  OK  ]

Make it Secure

The default mysql installation has some security loop holes such as empty root password, anonymous users, test database, etc. You need to remove all of these if you are going to use MySQL in production environment.

Run the following script:

/usr/bin/mysql_secure_installation

It will ask you different steps to remove all the security loop holes. Set the strict root password, remove remote access for root, remove anonymous users, and remove test database.

Verify mysql installation:

mysql -V

mysql  Ver 14.14 Distrib 5.1.45, for unknown-linux-gnu (x86_64) using readline 5.1

MySQL Configuration for Production Database

Now lets configure the mysql for the optimum production environment:

vi /etc/my.cnf

[mysqld]
socket=/var/lib/mysql/mysql.sock
datadir=/var/lib/mysql/data

By default mysql is installed under /var/lib/mysql and all the database created directly inside /var/lib/mysql. However, i prefer to use another folder under mysql named data for all the databases of mysql. That’s why i have set my datadir=/var/lib/mysql/data. If you want to use the same setting you will have to follow the following steps:

  1. stop mysql using service mysql stop
  2. create a new folder named data under /var/lib/mysql
  3. move all the files from /var/lib/mysql to /var/lib/mysql/data
  4. start mysql using service mysql start

It will be good if you enable binary logs on your server from start as you might need them for replication.

#replication master-server configuration
#server-id=1
#relay-log=/var/lib/mysql/logs/mysql-relay-bin
#relay-log-index=/var/lib/mysql/logs/mysql-relay-bin.index
log-error=/var/lib/mysql/logs/mysql.err
#master-info-file=/var/lib/mysql/logs/mysql-master.info
#relay-log-info-file=/var/lib/mysql/logs/mysql-relay-log.info
log-bin=/var/lib/mysql/logs/bin-logs
binlog-do-db=vbossdb
#binlog-ignore-db=
# end replication

Once you have set the above in your my.cnf you need to create logs directory under /var/lib/mysql/logs for binary and other logs of mysql.

Make sure mysql owns both data and mysql directories, you can do so using the following:

chown /var/lib/mysql/data mysql
chgrp /var/lib/mysql/data mysql
chown /var/lib/mysql/logs mysql
chgrp /var/lib/mysql/logs mysql

If most of your database is based on MyISM and you need best optimal performance for your MyISM tables use the following configuration. But make sure you change the values according to the RAM available on your system. I have 8GB RAM available on my server and want to use 3GB for my MyISAM tables as i have very large MyISAM tables with mysql partitions.

5 Comments
  1. Shoaib
    In Debian(Ubuntu) distribution you just need to write command on terminal and it will automatically install mysql server and client in your system
    //this command is use for installing server and client
    sudo apt-get install mysql-server-5.1
    //this command is use for installing client only
    sudo apt-get install mysql-client-5.1

    • skhanzada permalink

      Not everyone uses Debian 😉

      • In fedeora you need to write these two command to install mysql-server and mysql-client

        yum install mysql-server
        yum install mysql-client

      • skhanzada permalink

        These two lines only install in ideal world and will not work if i have already installed 5.0 or any previous version.

        Even if mysql is installed there are plenty of things to do to setup mysql for a production use as i’ve explained few of them above.

  2. TO un install mysql in debian distribution simply write
    sudo apt-get remove mysql-server-5.1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s