Linux modify mysql data file path

  

Many times, mysql data will be very large, the data is placed in /var/lib/mysql by default, because /var is not enough space, so we need to modify the mysql data storage path Put it in a large partition so that you can cope with mysql data growth.

1. Set a new storage path

mkdir -p /data/mysql

2. Copy the original data cp -R /var/lib/mysql/* /Data/mysql

3. Modify the permission chown -R mysql:mysql /data/mysql

4. Modify the configuration file vi /etc/mysql/my.cnfdatadir = /data/mysql

5. Modify the startup file vi /etc/apparmor.d/usr.sbin.mysqld

#put /var/lib/mysql r, /var/lib/mysql/** rwk,< Br>

#Change to /data/mysql r, /data/mysql/** rwk,

6. Restart the service restart apparmor/etc/init.d/apparmor restart/etc/init.d /mysql restart

The modification is now complete.

Appendix:

Exporting the database and compressing: mysqldump -u root -p mysql |  Gzip > mysql.sql.gz

Unpack: gunzip mysql.sql.gz

import: source mysql.sql

or mysqldump -uroot -p dbname < dbname .sql;

If it can't be started, check LOG:tail -n 40 /var/log/syslog

Configure the MySQL configuration data separately, solve the problem of large space occupied by ibdata1 file

Copyright © Windows knowledge All Rights Reserved