Installed MySQL changes the database file location

Source: Internet
Author: User
Tags chmod

Linux Systems:

Under Linux, the default data document storage directory for MySQL is/var/lib/mysql. The following steps are required if you want to move the MySQL directory to/home/data:

1. Set up the data directory in the home directory

Cd/home

mkdir data

2. Stop the MySQL service process:

Mysqladmin-u root-p shutdown

3. Move/var/lib/mysql Entire directory to/home/data

mv/var/lib/mysql/home/data/

This moves the MySQL data file to the/home/data/mysql.

4. Locate the MY.CNF configuration document

If there is no MY.CNF configuration document under the/etc/directory, locate the *.CNF document under/usr/share/mysql/, and copy one of them to/etc/and rename it to MY.CNF). The command is as follows:

[Email protected] mysql]# CP/USR/SHARE/MYSQL/MY-MEDIUM.CNF/ETC/MY.CNF

5. Edit the configuration document for MySQL/ETC/MY.CNF

To ensure that MySQL works correctly, you need to indicate where the Mysql.sock document is generated. Modify the value in the Socket=/var/lib/mysql/mysql.sock line to the right of the equals sign:/home/mysql/mysql.sock. The operation is as follows:

VI my.cnf (edit MY.CNF document with VI tool, find the following data to modify)

# The MySQL server

[Mysqld]

Port = 3306

#socket =/var/lib/mysql/mysql.sock (original content, in order to be more secure with "#" Comment this line)

Socket =/home/data/mysql/mysql.sock (plus this line)

6. Modify MySQL startup script/etc/init.d/mysql

Finally, you need to modify the MySQL startup script/etc/init.d/mysql, the path to the right of the equal sign in the Datadir=/var/lib/mysql line is changed to your current actual storage path: Home/data/mysql.

[Email protected] etc]# Vi/etc/init.d/mysql

#datadir =/var/lib/mysql (Note this line)

Datadir=/home/data/mysql (plus this line)

If it is CentOS also need to change/usr/bin/mysqld_safe relevant file location;

Finally make a mysql.sock link:
Ln-s/home/data/mysql/mysql.sock/var/lib/mysql/mysql.sock
7. Restart MySQL Service

/etc/init.d/mysql start

or restart Linux with the reboot command

If the work of the normal movement of success, or control the previous 7 steps to check again. Also pay attention to the owner and permission of the directory.

Copy Content to Clipboard
Code:
[[email protected] ~]# chown-r mysql:mysql/home/data/mysql/← Change the attribution of the database to MySQL

[[email protected] ~]# chmod 700/home/data/mysql/test/← Change the database directory property to 700

[[email protected] ~]# chmod 660/home/data/mysql/test/*← Change the property of the data in the database to 660

Installed MySQL changes the database file 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.