Wednesday 23 April 2014

Change the MySQL data default directory

Steps for MySQL data directory change,

Stopping the MySQL server

service mysql stop

Create a new data directory and move the content from the old data directory

mkdir /data/var/lib/mysql

chown mysql:mysql /data/var/lib/mysql

mv /var/lib/mysql/* /data/var/lib/mysql

Correct the MySQL configuration file

vi /etc/my.cnf


datadir = /data/var/lib/mysql

socket = /data/var/lib/mysql/mysql.sock

slow_query_log_file = /data/var/lib/mysql/mysql-slow.log

general_log_file = /data/var/lib/mysql/general.log


socket = /data/var/lib/mysql/mysql.sock

Adjust SELinux parameters to accept our new change


If semanage SELinux Command Not Found

yum install policycoreutils-python

man semanage

rpm -qf `which semanage`

semanage fcontext -a -t mysqld_db_t "/data/var/lib/mysql(/.*)?"

grep -i mysql /etc/selinux/targeted/contexts/files/file_contexts.local
/data/var/lib/mysql(/.*)?    system_u:object_r:mysqld_db_t:s0

restorecon -Rv data/var/lib/mysql

Starting the MySQL server

service mysql start

mysql -u root -p

mysql> show databases;

Optionally you can just use

mysql -u root -p --protocol tcp


No comments:

Post a Comment