In this post we will explain how to install MySQL on CentOS 6. MySQL is a well known relational database management system. It is open source and was first released in 1995. The source code is available under the GNU General Public License.
MySQL is a central component of LAMP web application software stack and is very popular for use in web applications like Joomla, WordPress, phpBB, TYPO3,… Since July 2013 MySQL is the worlds most widely used open source relational database management system.
Let’s start our Install MySQL on CentOS 6 Guide!
1. Install packages
The first step to install MySQL on CentOS is installing mysql-server and php-mysql packages and it’s dependencies:
[root@foo1 ~]# yum install mysql-server php-mysql -y
2. Start on boot
After a successfull package install we must enable MySQL daemon to start at boot time:
[root@foo1 ~]# chkconfig mysqld on [root@foo1 ~]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3. Edit configuration
Next we need to secure our MySQL instance.
Since we are not accessing our MySQL server from other servers, we will bind MySQL daemon to localhost by editing /etc/my.cnf file and adding an “bind-address=ipaddres” line:
[root@foo1 ~]# cat /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Bind to localhost bind-address=127.0.0.1
[mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
If you are accessing MySQL from other servers you can enter the IP addresses of the desired servers and separate them with a comma.
4. Start MySQL daemon:
[root@foo1 ~]# /etc/init.d/mysqld start Initializing MySQL database: WARNING: The host 'foo1.geekpeek.net' could not be looked up with resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MySQL version. The MySQL daemon, mysqld, should work normally with the exception that host name resolving will not work. This means that you should use IP addresses instead of hostnames when specifying MySQL privileges ! Installing MySQL system tables... OK Filling help tables... OK
To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system
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 foo1.geekpeek.net 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.
You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
[ OK ] Starting mysqld: [ OK ]
5. Set password
Next we can set the password for the MySQL root user:
[root@foo1 ~]# /usr/bin/mysqladmin -u root password 'myHardCorePass'
6. Connect to MySQL
Connect to MySQL instance as root and list existing databases:
[root@foo1 ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 4 Server version: 5.1.69 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec)
mysql>
We have completed our “Install MySQL on CentOS 6” guide. Your MySQL instance is installed and ready to use. Start creating filling them databases … 🙂