CentOS6 change the MySQL data storage location

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.