http://zlyang.blog.51cto.com/1196234/1726029
Requirements: MySQL database file original location:/var/lib/mysql to:/data/mysql
1. First create a folder named: MySQL in the/data directory:
# Mkdir/data/mysql
# Chown-r Mysql:mysql/data/mysql
# Chmod-r 755/data/mysql
2. Stop all MySQL services:
# Service HTTPD Stop
# Service Mysqld Stop
# Netstat-an |grep 3306//See if the MySQL service has stopped
3, copy the files under the/var/lib/mysql to the/data/directory:
# Mv/var/lib/mysql/data
4. Modify the configuration file:
# VI/ETC/MY.CNF
[Mysqld]
#datadir =/var/lib/mysql//original path
Datadir=/data/mysql//modified path
#socket =/var/lib/mysql/mysql.sock//Original sock path
Socket=/data/mysql/mysql.sock//Modified sock path
5. Modify the startup script:
# Vim/etc/init.d/mysqld
#get_mysql_option mysqld DataDir "/var/lib/mysql"//Original sock path
Get_mysql_option mysqld DataDir "/data/mysql"//Modified sock path
6. Start the MySQL service:
# service Mysqld Start
# service httpd Start
# Mysql-uroot-p//test can log in normally;
Error 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock '///If the error occurs, do the following:
# Mkdir/var/lib/mysql
# ln-s/data/mysql/mysql.sock/var/lib/mysql/mysql.sock
7, after the implementation of the above operation, the migration of database files has been completed.
MySQL Mobile database location