MySQL defaults to the data file storage directory for/var/lib/mysql. If you want to move the MySQL directory to/home/data, you need to do the following steps:
1, the home directory to establish the data directory
Cd/home
mkdir data
2, the MySQL service process to stop:
Mysqladmin-u root-p shutdown
3. Move/var/lib/mysql Entire directory to/home/data
mv/var/lib/mysql/home/data/
This will be the MySQL data file moved to the/home/data/mysql
4, find my.cnf configuration file
If there is no MY.CNF configuration file in the/etc/directory, please find *.cnf file under/usr/share/mysql/, copy one to/etc/and rename to my.cnf). The order is as follows:
[Root@test1 mysql]# cp/usr/share/mysql/my-medium.cnf/etc/my.cnf
5, edit the MySQL configuration file/etc/my.cnf
To ensure that MySQL works properly, you need to indicate where the Mysql.sock file will be generated. Modify the value on the right side of the equal sign in Socket=/var/lib/mysql/mysql.sock line:/home/mysql/mysql.sock. The operation is as follows:
VI my.cnf (with VI tool to edit MY.CNF file, find the following data modification)
# The MySQL server
[Mysqld]
Port = 3306
#socket =/var/lib/mysql/mysql.sock (original content, in order to be more secure with "#" comment on this row)
Socket =/home/data/mysql/mysql.sock (plus this row)
6, modify the MySQL startup script/etc/init.d/mysql
Finally, you need to modify the MySQL startup script/etc/init.d/mysql, datadir=/var/lib/mysql the path to the right of the equal sign in one line, and change it to your current actual storage path: Home/data/mysql.
[Root@test1 etc]# Vi/etc/init.d/mysql
#datadir =/var/lib/mysql (note this row)
Datadir=/home/data/mysql (plus this row)
7, restart the MySQL service
/etc/init.d/mysql start
or restart Linux with the reboot command
If the work is moving normally, it will be successful, otherwise check the previous 7 steps.
Also pay attention to the owner and permissions of the directory.