Installing MySQL on CentOS is very simple using the 'yum' package manager.
This article will go through the install process and also look at what other packages are needed for MySQL to integrate with Ruby on Rails and with a standard PHP install.
To begin with, a simple MySQL install:
sudo yum install mysql-server mysql mysql-devel
Note that we have installed the development libs and headers with the 'mysql-devel' package. This package is required by the mysql Rubygems package which we install later in this article.
We need to start the MySQL server to intiliaze the installation of the base MySQL databases.
sudo /etc/init.d/mysqld start
During the process, you will be presented with instructions to install a password for the root MySQL user:
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password'
Setting the MySQL Root password is a recommended step in setting up your Slice. However, it is, of course, up to you.
Should you decide that protecting your production database is a good idea, then simply enter your chosen password as directed.
MySQL Password Confirmation
Let's confirm that our password is working as expected.
mysql -uroot -ppassword
Replace 'password' with the one you set in the previous step.
The result should be a successful login to MySQL:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.0.45 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
OK and exit MySQL.
Done. It really is as simple as that.
MySQL and Ruby on Rails
I am assuming you have Ruby on Rails installed at this stage (if not, please see the CentOS - Ruby on Rails article).
All we need to do is install one package as follows:
sudo gem install mysql -- --with-mysql-config=/usr/lib64/mysql/mysql_config
By default the install process looks for the mysql_config file in '/usr/lib'. However, as we have installed the 64bit version of MySQL, we need to specify the correct location as shown above.
Seems suspiciously easy. Let's conduct a quick test to see if all is well:
irb #irb(main):001:0> require 'rubygems' => true #irb(main):002:0> require 'mysql' => true
That seems fine to me.
MySQL and PHP
If you installed Apache and PHP using the CentOS - Apache and PHP article, you will already have the PHP MySQL module installed (which is 'php5-mysql').
This simple process also installs the PHP 'mysqli' (MySQL improved extension) module. This allows for much more powerful MySQL usage within PHP - please see the PHP mysqli page for more details.
A standard phpinfo page shows the following information for the mysql and mysqli modules:
As you can see, installation is very easy.
Installing MySQL via the 'yum' package manager is very simple and ensures you have any security updates if and when they are released.
Installing the necessary packages for MySQL to integrate with Ruby on Rails and PHP is a suitably easy process - allowing you to concentrate on the site design rather than messing with the installation itself.