======Install MySQL======
This page shows how to install MySQL on CentOS 6 64bit.
=====Prerequisites=====
You must have a CentOS machine already set up in accordance with the the [[linux:install_centos6|Install CentOS 6]] guide.
=====Install MySQL=====
Install the MySQL server. Run all the following commands as root.
yum -y install mysql mysql-server
Configure MySQL server to start automatically on system boot.
chkconfig mysqld on
Start the MySQL server.
service mysqld start
=====Secure MySQL=====
Run the following command to set good security measures on the database.
mysql_secure_installation
# Current root password is nothing (e.g. just press enter without typing anything else)
# Set Root password for database (Use administrator password)
# Remove anonymous users
# Disallow root login remotely
# Remove test database and access to it
# Reload privilege tables now
=====Move MySQL Data Store=====
We can move the data store to a separate partition.
Assuming /data exists (which it will for a lot of our Linux servers), move the MySQL data directory to the second disk.
service mysqld stop
mkdir -p /data/mysql
chown mysql:mysql /data/mysql
su - mysql
cp -R /var/lib/mysql/* /data/mysql
# Note: For the following command, ignore the message about not being able to delete some directories. That is what we want.
rm -f /data/mysql/*
exit
Edit /etc/my.cnf
sed -i "s/\/var\/lib\/mysql/\/data\/mysql/g" /etc/my.cnf
sed -i "s/\/var\/lib\/mysql\/mysql.sock/\/data\/mysql\/mysql.sock/g" /etc/my.cnf
Also run the following
FILENAME=/etc/my.cnf
echo '' >> $FILENAME
echo '[client]' >> $FILENAME
echo 'socket = /data/mysql/mysql.sock' >> $FILENAME
Edit /etc/php.ini
sed -i "s/mysql.default_socket\ =/mysql.default_socket\ =\ \/data\/mysql\/mysql.sock/g" /etc/php.ini
sed -i "s/mysqli.default_socket\ =/mysqli.default_socket\ =\ \/data\/mysql\/mysql.sock/g" /etc/php.ini
Configure SELinux to allow MySQL data to be used from the separate drive.
semanage fcontext -a -t mysqld_db_t "/data/mysql(/.*)?"
restorecon -Rv /data/mysql
Start MySQL
service mysqld start
Restart Apache web server to pickup the PHP changes.
service httpd restart
=====Install PHPMyAdmin=====
For installing some PHP modules (like php-mycrypt, etc which is needed for phpMyAdmain), we need to [[RPM#Install_EPEL_Repository_on_CentOS_6| enable EPEL]].
yum -y install php php-mysql php-common php-gd php-mbstring php-mcrypt php-xml php-soap
yum -y install phpMyAdmin
service httpd restart
View the interface at ''http://machine/phpMyAdmin''.