Installing Latest Version of MySQL on Linux (CentOS 6) Production Server

Checking if MySQL is Already Installed

[ahmed@amayem ~]$ rpm -q mysql-server
package mysql-server is not installed

Or you can do it this way:

[ahmed@amayem ~]$ yum list installed | grep mysql
[ahmed@amayem ~]$

Downloading the MySQL Yum Repository Release Package:

Choose your operating system from http://dev.mysql.com/downloads/repo/yum/
In my case it was CentOS 6, which means I would want to get EL 6. This one is 64 bit. To get the 32 bit check here:

[ahmed@amayem ~]$ wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
–2014-08-28 22:59:50– http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
Resolving dev.mysql.com… 137.254.60.11
Connecting to dev.mysql.com|137.254.60.11|:80… connected.
HTTP request sent, awaiting response… 302 Found
Location: http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm [following]
–2014-08-28 22:59:50– http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
Resolving repo.mysql.com… 23.202.216.96
Connecting to repo.mysql.com|23.202.216.96|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 5824 (5.7K) [application/x-redhat-package-manager]
Saving to: `mysql-community-release-el6-5.noarch.rpm’

100%[====================================>] 5,824 –.-K/s in 0s

2014-08-28 22:59:51 (741 MB/s) – `mysql-community-release-el6-5.noarch.rpm’ saved [5824/5824]

[ahmed@amayem ~]$ ls
mysql-community-release-el6-5.noarch.rpm

We have the rpm.
Installing the MySQL Yum Repository Release Package

Now that we have the release package, it’s time to install it:

[ahmed@amayem ~]$ sudo yum localinstall mysql-community-release-el6-5.noarch.rpm

There will be quite a bit of output, and there should be a prompt that looks something like the following:

Total size: 4.3 k
Installed size: 4.3 k
Is this ok [y/N]:

Of course accept with y or Y. Some more output will be displayed, which should end with something like the following:

Installed:
mysql-community-release.noarch 0:el6-5

Complete!

Checking the Version of the Available Mysql

[ahmed@amayem ~]$ yum info mysql-community-server

You will see quite a bit of output that I have truncated, but in the end the relative info should be displayed:

Available Packages
Name : mysql-server
Arch : i686
Version : 5.1.73
Release : 3.el6_5
Size : 8.8 M
Repo : updates
Summary : The MySQL server and related files
URL : http://www.mysql.com
License : GPLv2 with exceptions
Available Packages
Name : mysql-community-server
Arch : i686
Version : 5.6.20
Release : 4.el6
Size : 51 M
Repo : mysql56-community
Summary : A very fast and reliable SQL database server
URL : http://www.mysql.com/
License : Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field.

Notice that there are two packages:

mysql-server
mysql-community-server

mysql-server is the one provided by the default yum repositories. mysql-community-server is the one provided by our newly installed MySQL yum repository, which should be the latest stable release. To install any other version check here.
Installing

If you are happy with the version then it’s time to install:

[ahmed@amayem ~]$ yum install mysql-community-server
Loaded plugins: fastestmirror
You need to be root to perform this command.

Oops we need to use sudo. Check here to see how to give a linux user sudo powers:

[ahmed@amayem ~]$ sudo yum install mysql-community-server

There will be quite a bit of output, and there should be a prompt that looks something like the following:

Total download size: 70 M
Installed size: 292 M
Is this ok [y/N]:

Of course accept with y or Y. Some more output will be displayed followed by another prompt that looks like the following:

warning: rpmts_HdrFromFdno: V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : MySQL Release Engineering <mysql-build@oss.oracle.com>
Package: mysql-community-release-el6-5.noarch (@/mysql-community-release-el6-5.noarch)
From : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]:

This is just a way to check that what has been downloaded so far has not been corrupted. Accept with y or Y. The tests should succeed. The output should end with the following:

Complete!

Starting MySQL

[ahmed@amayem ~]$ sudo service mysqld start
Initializing MySQL database:

There is more output that I have truncated. It should end with something like this:

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’
/usr/bin/mysqladmin -u root -h amayem.amayem.com password ‘new-password’

Alternatively you can run:

/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

Note: new default config file not created.
Please make sure your config file is current

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
–defaults-file argument to mysqld_safe when starting the server

[ OK ]
Starting mysqld: [ OK ]

Securing the Installation

As mentioned in the above output, if we are running this on a production server then we should do a secure installation as follows:

[ahmed@amayem ~]$ mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):

This should be the first time, so we shouldn’t have a password yet. Just press enter.

OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n]

Enter Y and enter your new password:

New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]

If you are running on a production server then you should definetely press Y.

Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]

Once again if you are in production then enter Y. In fact enter Y for all the questions if you are in production:

By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
– Dropping test database…
ERROR 1008 (HY000) at line 1: Can’t drop database ‘test’; database doesn’t exist
… Failed! Not critical, keep moving…
– Removing privileges on test database…
… Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
… Success!
All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Congratulations you are done. Now let’s see if mysql will survive a reboot:
Surviving a reboot

First let’s check that it is running:

[ahmed@amayem ~]$ ps -e | grep mysql
683 pts/0 00:00:00 mysqld_safe
887 pts/0 00:00:00 mysqld

That looks right. Alternatively:

[ahmed@amayem ~]$ sudo service mysqld status
mysqld (pid 887) is running…

Now let’s reboot and see if we get the same thing:

[ahmed@amayem ~]$ sudo reboot

Wait a bit then login again, and repeat the above:

[ahmed@amayem ~]$ sudo service mysqld status
mysqld is stopped

So it does not automatically run on reboot. We need to setup the init.d script:

[ahmed@amayem ~]$ cd /etc/init.d/

We should see a mysqld file, that was put there with the install:

[ahmed@amayem init.d]$ ls | grep mysql
mysqld

The script is there but is it being used?

[ahmed@amayem init.d]$ chkconfig –list | grep mysql
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off

It’s off for everything. Let’s turn it on for level 3:

[ahmed@amayem init.d]$ sudo chkconfig –level 3 mysqld on
[ahmed@amayem init.d]$ chkconfig –list | grep mysql
mysqld 0:off 1:off 2:off 3:on 4:off 5:off 6:off
[ahmed@amayem init.d]$

Now let’s reboot again and test:

[ahmed@amayem init.d]$ sudo service mysqld status
mysqld is stopped
[ahmed@amayem init.d]$ sudo service mysqld start
Starting mysqld: [ OK ]
[ahmed@amayem init.d]$ sudo service mysqld status
mysqld (pid 1159) is running…
[ahmed@amayem init.d]$ sudo reboot
[ahmed@amayem init.d]$
Broadcast message from ahmed@amayem.amayem.com
(/dev/pts/1) at 1:17 …

Now let’s test:

[ahmed@amayem ~]$ sudo service mysqld status
mysqld (pid 733) is running…

Advertisements
Leave a comment

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

%d bloggers like this: