A basic example
Linux MySQL changes the directory location of the MySQL database
The default data file storage directory of MySQL is/var/lib/mysql. To move the directory to/home/data, perform the following steps:
1. Create a data directory under the home Directory
Cd/homemkdir data
2. Stop the MySQL service process:
Mysqladmin-u root-p shutdown
3. Move the entire/var/lib/mysql directory to/home/data
Mv/var/lib/mysql/home/data/
In this way, the MySQL data file is moved to/home/data/mysql.
4. Find the my. cnf configuration file.
If my. the cnf configuration file (www.avnads.cn) can be found under/usr/share/mysql *. copy one of the cnf files to/etc/and change it to my. cnf. The command 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 must specify the location where the mysql. sock file is generated. Change socket =/var/lib/mysql. sock to/home/mysql. sock. The procedure is as follows:
Vi my. cnf (use vi tool to edit my. cnf file, find The following data to modify) # The MySQL server [mysqld] port = 3306 # socket =/var/lib/mysql. sock (original content, to make it more secure to use "#" to comment out this line) socket =/home/data/mysql. sock (previous line)
6. Modify the MySQL STARTUP script/etc/init. d/mysql
Finally, you need to modify the MySQL STARTUP script/etc/init. d/mysql: change the path on the Right of datadir =/var/lib/mysql to your actual storage path: home/data/mysql.
[Root @ test1 etc] # vi/etc/init. d/mysql # datadir =/var/lib/mysql (comment this line) datadir =/home/data/mysql (previous line)
7. Restart the MySQL service.
/Etc/init. d/mysql start
Or use the reboot command to restart Linux.
If it works properly, it will succeed. Otherwise, check again against the previous seven steps. Pay attention to the owner and permissions of the directory.