If you want to move the directory to/home/data under the following steps: 1, the home directory to establish the data directory cd/home mkdir data 2, the MySQL service process is stopped: mysqladmin-u root-p shutdown 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 4, find the MY.CNF configuration file if/ etc/directory does not have a my.cnf configuration file, please find the *.cnf file under/usr/share/mysql/, copy one of them to/etc/and rename it to MY.CNF). The command is as follows: [[[Email protected] mysql]# cp/usr/share/mysql/my-medium.cnf/etc/my.cnf 5, edit the configuration file for MySQL/etc/my.cnf to ensure mysq L can work properly and need to indicate where the Mysql.sock file is generated. Modify the value in the Socket=/var/lib/mysql/mysql.sock line to the right of the equals sign:/home/mysql/mysql.sock. Operation is as follows: VI my.cnf (edit my.cnf file with VI tool, find the following data to modify) # The MySQL server [mysqld] Port = 3306 #socket =/var/lib/ Mysql/mysql.sock (original content, in order to be more secure with "#" comment this line) socket =/home/data/mysql/mysql.sock (plus this line) 6, modify the MySQL startup script/etc/init.d/mysql Finally, The MySQL startup script needs to be modified/etc/init.d/mysql, and the path to the right of the equal sign in the Datadir=/var/lib/mysql line is changed to your current actual storage path: Home/data/mysql. [[email protected] etc]# vi/etc/init.d/mysql #datadir =/var/lib/mysql (note this line) Datadir=/home/data/mysql (plus this line) 7. Restart the MySQL service/etc/init.d/mysql start or restart Linux with the reboot command if the work moves successfully, otherwise check the previous 7 steps. Also pay attention to the owner and permission of the directory.
How Linux MySQL moves the MySQL database directory location