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

[mysqld]

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

[client]

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

Adjust SELinux parameters to accept our new change

getenforce
Disabled

If semanage SELinux Command Not Found

yum install policycoreutils-python

man semanage

rpm -qf `which semanage`
policycoreutils-python-2.0.83-19.39.el6.x86_64

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


Ref:-  

 http://crashmag.net/change-the-default-mysql-data-directory-with-selinux-enabled

https://blogs.oracle.com/jsmyth/entry/selinux_and_mysql

https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Managing_Confined_Services/sect-Managing_Confined_Services-MySQL-Configuration_Examples.html

No comments:

Post a Comment