Thursday, October 17, 2013

Installing MySQL in Linux

MySQL is a very powerful open source relational database management system (RDBMS). In this short guide we'll get into installing MySQL on Linux.

You can check whether MySQL is already installed by issuing the following command.
$ mysql -V
You should see something similar output as follows if you have MySQL installed.
mysql  Ver 14.14 Distrib 5.5.32, for debian-linux-gnu (x86_64) using readline 6.2
If not, to install MySQL, run the following command from a terminal prompt in apt-get package manager based Linux distributions
$ sudo apt-get install mysql-server
In yum package manager based Linux distributions, issue the following command
$ sudo yum install mysql-server
You will be prompted to enter a password for the MySQL root user in the installation process. It's recommended to use a password for a root account. Now the MySQL server is installed on your Linux machine.

Alternatively, you may download the relevant MySQL package (e.g. rpm package) for your Linux from and install according to your distribution. You may need to sign up for an Oracle Web account to download from this site. This article won't go into details of installing with distribution specific packages.

MySQL installation could also be done with the source. You can also download the source distribution from the above URL. Installing from source needs certain tools and libraries pre-installed (such as cmake and ncurses-devel). Other workaround may be required to build from source.

To start the MySQL database, issue the following command.
$ sudo /etc/init.d/mysql start
or in Fedora/RHEL
$ sudo systemctl start mysqld.service
To check whether MySQL is already running, you can issue the following command.
$ mysqladmin -u root -p status
You will be prompted for the password. When entered, you should see somewhat similar output as follows if MySQL is running
Uptime: 28581  Threads: 1  Questions: 111  Slow queries: 0  Opens: 343  Flush tables: 1  Open         tables: 84  Queries per second avg: 0.003
If not running, you would see an output as shown below.
   mysqladmin: connect to server at 'localhost' failed
   error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
   Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
You can edit the settings for the MySQL instance in /etc/mysql/my.cnf file to configure the basic settings like log file and port number.

That's it. You now should have MySQL installed on your system and ready to use it to develop database driven applications.

No comments:

Post a Comment