This installation guide will show you how to install, configure and test MySQL 5 on the CentOS 6 operating system. We will go through the following steps.
CentOS Base Install
Log in to your server as root
The first step on a bare CentOS OS install is to install some dependencies. Firstly we need to install wget to download the latest version of MySQL. We also need to install Perl before we install mysql to do this we use the following commands
yum install wget
yum install perl
yum install libaio
Download the version of MySQL you would like to install. In this case we are installing that latest available CE edition 5.6.11-2
If you are running 64 bit CentOS
wget dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.11-2.el6.x86_64.rpm/from/http://cdn.mysql.com/
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.11-2.el6.x86_64.rpm/from/http://cdn.mysql.com/
wget dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.11-2.el6.x86_64.rpm/from/http://cdn.mysql.com/
If you are running 32 bit CentOS
wget dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.11-2.el6.i686.rpm/from/http://cdn.mysql.com/
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.11-2.i686.rpm/from/http://cdn.mysql.com/
wget dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.11-2.el6.i686.rpm/from/http://cdn.mysql.com/
If your not sure if it’s 32 bit or 64 use the uname -m command if it x86_64 it’s 64 if it’s i686 it’s 32 bit
uname -m
i686
The next step is to install the newly downloaded packages.
rpm -ih MySQL-shared-5.6.11-2.el6.i686.rpm
rpm -ih MySQL-client-5.6.11-2.el6.i686.rpm
rpm -ih MySQL-server-5.6.11-2.el6.i686.rpm
If you have an old version of MySQL installed you may see an error like file /usr/share/mysql/english/errmsg.sys from install of MySQL-server-5.6.11-2.el6.i686 conflicts with file from package mysql-libs-5.1.47-4.el6.i686
when installing the server rpm. This can be resolved with the following command
rpm --nodeps -e mysql-libs
With MySQL succesfully installed you will see the following output
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.
You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!
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
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
MySQL Services
The basic command to start, stop and restart mySQL are as follows.
service mysql start
service mysql stop
service mysql restart
If you want mysql to restart when the server reboots
chkconfig mysql --level 2345 on
MySQL Configuration
With MySQL started it is now time to log on for the first time and set up some basic configuration. The default password will be in a text file at /root/.mysql_secret and the first time you are logged on you will be forced to change it. We can then create a new database, database user and table to show that it is working. The commands are as follows
mysql -u root -p
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('topsecret');
mysql> create database testdb;
mysql> use testdb;
GRANT ALL PRIVILEGES ON testdb.* TO [email protected] IDENTIFIED BY 'myusersecret';
mysql> quit
Bye
[[email protected] ~]# mysql -u myuser -p testdb
Enter password:
mysql> CREATE TABLE person (id INT, name VARCHAR(20), email VARCHAR(20));
To make sure you haven’t left any sensitive information in the command history make sure you clear it as follows
cat /dev/null > ~/.mysql_history
Don’t forget to clean up the install files
rm -f MySQL-client-5.6.11-2.el6.i686.rpm
rm -f MySQL-server-5.6.11-2.el6.i686.rpm
rm -f MySQL-shared-5.6.11-2.el6.i686.rpm
rm -f /root/.mysql_secret