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.
Copy codeThe Code is as follows:
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.
Copy codeThe Code is as follows:
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.
Copy codeThe Code is as follows:
[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.
Copy codeThe Code is as follows:
[Mysql]
Mysql. default_socket =/home/mysql. sock
[Mysqli]
Mysql. default_socket =/home/mysql. sock
5. Start apache. mysql.
Copy codeThe Code is as follows:
Service httpd start
Service mysqld start