CentOS6 change the MySQL data storage location
When mysql is installed using yum, the default data is stored in/var/lib/mysql. Generally, to ensure data security, we recommend that you store the mysql database data files in the directory of the second disk in the system by performing the following steps;
1. Disable selinux and mysqld.
Sed-I's/enforcing/disabled/G'/etc/selinux/config
Setenforce 0
Service mysqld stop <br> chkconfig mysqld off
2. Mount the second Hard Disk/dev/sdb of the system and edit the/etc/fstab file to set automatic mounting upon startup.
Fdisk/dev/sdb
N p w
Mkfs-t ext4/dev/sdb1
Fdisk-l <br> mkdir/data <br> mount/dev/sdb1/data <br> df-hT <br> vi/etc/fstab
3. Back up the stored database files
Since the new data storage directory/data/db will be mounted to/var/lib/mysql, You need to temporarily store the data under/var/lib/mysql.
Mv/var/lib/mysql/var/lib/mysqlbak
Mkdir/var/lib/mysql
4. Mount directory
Mount the newly added MySQL data storage directory/data/db to/var/lib/mysql
Mount -- bind/date/var/lib/mysql
5. Restore data in the mysql database
Cd/var/lib/
Yes | cp-r mysqlbak/* mysql/
6. Set directory permissions to ensure normal use of your mysql database
Chown-R mysql: mysql/var/lib/mysql
Chown-R mysql: mysql/data
Chkconfig mysqld on
7. Restart the mysql service.
Services mysqld restart
8. Set mysql startup to ensure that your mysql Server can be started with the host every time it is restarted.
Cat>/etc/rc. d/rc. local
Service mysqld stop
Mount -- bind/data // var/lib/mysql
Service mysqld start
Services mysqld restart
Press CTRL + D and press Enter.
9. test whether the Mysql location is changed successfully.
Here we cp a file in it and we will naturally be synchronized to the second block, as shown in:
This article permanently updates the link address: