Original: http://www.cnit618.com/html/fwdkf/data/2111.htm
Under Linux, the default data document storage directory for MySQL is/var/lib/mysql. The following steps are required if you want to move the MySQL directory to/home/data:
1. Set up the data directory in the home directory
Cd/home
mkdir data
2. Stop the MySQL service process:
Mysqladmin-u root-p shutdown
3. Move/var/lib/mysql Entire directory to/home/data
mv/var/lib/mysql/home/data/
This moves the MySQL data file to the/home/data/mysql.
4. Locate the MY.CNF configuration document
If there is no MY.CNF configuration document under the/etc/directory, locate the *.CNF document under/usr/share/mysql/, and 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 document for MySQL/ETC/MY.CNF
To ensure that MySQL works correctly, you need to indicate where the Mysql.sock document 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. The operation is as follows:
VI my.cnf (edit MY.CNF document 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 MySQL startup script/etc/init.d/mysql
Finally, you need to modify the MySQL startup script/etc/init.d/mysql, 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)
If it is CentOS also need to change/usr/bin/mysqld_safe relevant file location;
finally make a mysql.sock link:
Ln-s/home/data/mysql/mysql.sock/var/lib/mysql/mysql.sock
7. Restart MySQL Service
/etc/init.d/mysql start
or restart Linux with the reboot command
If the work of the normal movement of success, or control the previous 7 steps to check again. Also pay attention to the owner and permission of the directory.
Copy Content to Clipboard
Code:
[[email protected] ~]# chown-r mysql:mysql/home/data/mysql/← Change the attribution of the database to MySQL
[[email protected] ~]# chmod 700/home/data/mysql/test/← Change the database directory property to 700
[[email protected] ~]# chmod 660/home/data/mysql/test/*← Change the property of the data in the database to 660