MySQL database migration data folder location detailed steps bitsCN.com
Because the data directory of the database is under/var/lib by default when mysql is installed in yum, it needs to be moved to the/data partition for data security considerations. The procedure is as follows:
1. disable apache and mysql.
Service httpd stop
Service mysqld stop
2. move the mysql directory mv under/var/lib to the data directory.
Why the mv command instead of the cp command? For linux file systems, mv commands can retain all attributes and permissions of files, especially selinux attributes. If you use the cp command, you need to go back and set the selinux attribute of the mysql folder. because of the headache, selinux can be avoided.
Mv-R/var/lib/mysql/data/mysql
3. modify the mysql configuration file/etc/my. cnf. Change the datadir and socket paths to the/data Directory.
[Mysqld]
# Datadir =/var/lib/mysql ------ default path of the original system
Datadir =/home/mysql ------ existing path
# Socket =/var/lib/mysql. sock ------ the original socket path is now
Socket =/home/mysql. sock ------ Current path
[Mysqld_safe]
Socket =/home/mysql. sock ----- current path
[Client]
Socket =/home/mysql. sock ----- current path
[Mysql. server]
Socket =/home/mysql. sock ----- current path
4. modify the socket path in the php configuration file (/etc/php. ini.
Sure, do not forget to specify the socket path in php. ini. Otherwise, the php website will not be able to connect to the database. In php. ini, the default socket path is null. the default path is/var/lib/mysql. Therefore, you must change it to/data/mysql.
[Mysql]
Mysql. default_socket =/home/mysql. sock
[Mysqli]
Mysql. default_socket =/home/mysql. sock
5. start apache. mysql.
Service httpd start
Service mysqld start
BitsCN.com