There are plenty of methods available to install MySQL on Centos. Among those methods, most recommended way is, installing MySQL from standard source distribution, because it will allow to customize the installation as you wish and able to add other modules as well. This tutorial guide you how to build MySQL from source with few easy steps.
1) Download latest MySQL source.
http://www.mysql.com/downloads/
2) Create user and group called “mysql”
1 2 |
[root@localhost]#groupadd mysql [root@localhost]#useradd -r -g mysql mysql |
3) Install depended software packages.
You may need following packages. it will totally depend on your Linux distribution.
Loot at how to install perl for MySQL from here.
1 2 3 4 |
[root@localhost]#yum install gcc gcc-c++ cmake [root@localhost]#yum install cmake [root@localhost]#yum install ncurses-devel [root@localhost]#yum install perl perl-devel |
4) build MySQL
Sometimes cMake give you errors. So don’t get panic, find the error and fixed it. Most of the time you need to install some missing package. After that DON’T FORGET to delete CMakeFiles content and, CMakeCache.txt before cMake again.
1 2 3 4 5 |
[root@localhost]#tar zxvf mysql-VERSION.tar.gz [root@localhost]#cd mysql-VERSION [root@localhost]#cmake . [root@localhost]#make [root@localhost]#make install |
5) Configure MySQL
here assuming MySQL database directory as /opt/mysql/data. Otherwise it will goes to default location.
1 2 3 4 5 6 7 |
[root@localhost]#cd /usr/local/mysql [root@localhost]#chown -R mysql . [root@localhost]#chgrp -R mysql . [root@localhost]#mkdir -p /opt/mysql/data [root@localhost]#chown -R mysql.mysql /opt/mysql [root@localhost]#scripts/mysql_install_db --user=mysql --datadir=/opt/mysql/data [root@localhost]#chown -R root . |
6) Start MySQL
Set MySQL up start script and then start the MySQL server.
1 2 |
[root@localhost]#cp support-files/mysql.server /etc/init.d/mysql [root@localhost]#service mysql start |
7) Set MySQL root password
1 2 |
[root@localhost]#cd /usr/local/mysql [root@localhost]#./bin/mysqladmin -u root password 'yournewpassword' |
Wow, how cool it is. Comment here if you got any issue.
Note :- below is sample my.cnf file with basic configuration .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[client] port = 3306 socket = /opt/mysql/mysql.sock [mysqld] port = 3306 socket = /opt/mysql/mysql.sock bind-address = 192.168.1.10 ##mysql server ip address #directories basedir=/usr/local/mysql datadir=/opt/mysql/data pid-file=/usr/local/mysql/data/mysql_server.pid log-error=/opt/mysql/data/mysql_server.err plugin-dir=/usr/local/mysql/lib/plugin [mysqld_safe] basedir=/usr/local/mysql datadir=/opt/mysql/data pid-file=/usr/local/mysql/data/mysql_server.pid |