MySQL Modify database file storage location

Source: Internet
Author: User

In CentOS7, the MySQL database file is placed by default in/var/lib, and sometimes the partition is smaller, it needs to be migrated to the larger partition, by the following method

1. Stop the MySQL service and copy the/var/lib/mysql directory to a new directory, such as/home/mysql
Cp-r/var/lib/mysql/home/

2, modify the/etc/my.conf, find the following two lines:

Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Change into
Datadir=/home/mysql
Socket=/home/mysql/mysql.sock

3. This time if restarting the MySQL service will error:
Job for Mysqld.service failed because the control process exited with error code. See "Systemctl Status Mysqld.service" and "Journalctl-xe" for details.

when installing MySQL, a MySQL user and a MySQL user group were created, and the directory where the files were stored/var/lib/mysql the MySQL user, and after the migration,/home/mysql belonged to the root user and the ROot user group. (This depends on what account you use to log in to CentOS.) In this case, it is only possible to belong to the root user, because the general user does not have permission to write in home/home, MySQL must not have permission to operate the file belonging to the root, so the error.
Modify the/home/mysql directory and the properties of all the files below to make them belong to the MySQL user

Chown-r Mysql:mysql \home\mysql

4, after completing the above steps still cannot start the MySQL service, because of the selinux limit, turn it off, modify the/etc/selinux/config file:
Selinux=disabled

Finally restart the MySQL service

MySQL Modify database file storage location

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.