Http://www.cnblogs.com/chenny7/p/3642363.html
This article mainly describes how to move the default data directory to the specified location after installing MySQL under the Yum command under CentOS.
Install MySQL:
Yum-y Install Mysql-server mysql-client
After Mysql installation, the default data file storage directory is/var/lib/mysql.
The following steps are required if you want to move the directory to/home/data:
1. Set up the data directory in the home directory
Cd/homemkdir data
2. Stop the MySQL service process:
Service Mysqld Stop
3. Move/var/lib/mysql Entire directory to/home/data
mv/var/lib/mysql/home/data/
This will move the MySQL data file to/home/data/mysql.
Then create a new empty directory again and make a soft connection to the new sock path:
Mkdir/var/lib/mysqlln-s/home/data/mysql/mysql.sock/var/lib/mysql/mysql.sock
4, VIM/ETC/MY.CNF
If the/etc/directory does not have a MY.CNF profile, locate the *.cnf file under/usr/share/mysql/, copy one of them to/etc/and rename it to MY.CNF.
To ensure that MySQL works correctly, you need to indicate where the Mysql.sock file is generated. Modify
5, Vim/etc/init.d/mysqld
Datadir=/home/data/mysql
If it is CentOS also need to change/usr/bin/mysqld_safe relevant file location;
6, Vim/usr/lib64/mysql/mysql_config
socket= '/home/data/mysql/mysql.sock ' ldata= '/home/data/mysql '
7. Restart MySQL Service
Service mysqld Start
If the work is moving properly, otherwise check the previous 7 steps.
Also note that the owner and permission of the directory, the code is as follows:
Chown-r Mysql:mysql/home/data/mysql/chmod 700/home/data/mysql/test/chmod 660/home/data/mysql/test/*
Finally, check the log/var/log/mysqld.log if you find can ' t create test file/xxx/mysql/centos5.lower-test
This is because there is no permission to create or read files.
The solution is to use the Setenforce 0 command, let the system turn off the check of permissions, and then run the command service mysqld start found OK.
Another way is restorecon-frv/home/data/mysql, or chcon-r-t mysqld_db_t/home/data/mysql
MySQL changes the default data directory