After using the VPS for a period of time, you find that the disk space is almost full. My VPS bought a 500GB disk at the time of purchase, and the provider presented a 20GB high-performance system disk. So the system has two disk space. The database directory was installed on the system disk when MySQL was first installed. (first disk) after a period of time, the database storage volume is large, the storage space of 20GB is full. Therefore, the storage space must be changed. Hey, the following is a simple operation, unreasonable point also please the heroes.
Operation Steps:
1. Check the MySQL database storage directory
Mysql-u Root-prootadmin
#进入数据库
Show variables like '%dir% ';
#查看sql存储路径
(View the path indicated by the DataDir line)
Quit
2. Stop the MySQL service
Service Mysqld Stop
3. Create a new database storage directory
Mkdir/data/mysql
4. Move/copy before storing the database directory files, to the new database storage directory location
Cp-r/usr/local/mysql/data/*/data/mysql/#或mv/usr/local/mysql/data/*/data/mysql
5. Modify MySQL Database directory permissions and configuration files
Chown Mysql:mysql-r/data/mysql/
Vim/etc/my.cnf
Datadir=/data/mysql (developed as a new data storage directory)
Vim/etc/init.d/mysqld
Datadir=/data/mysql
6. Start the database service
Service mysqld Start
Description: Based on the above simple 6-step operation, the database directory has been successfully replaced the path.
Note: The above system is CentOS 6.2 x64 mysql-5.5.13
MySQL database storage path change data file location