Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change the path of MYSQL data storage

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about how to change the path of MYSQL data storage, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

In fact, this is not only a relational database management system, but also one of today's relational database management systems, which is characterized by being able to save in different tables, greatly improving access speed and flexibility. Today, the editor introduces the way to change the MY SQL data storage path.

In general, the default data file storage directory for MySQL is / var/lib/mysql. If you want to move the directory under / home/database, you need to take the following steps:

1. First set up the database directory under the home directory

Command: cd/homemkdir data

2. Next, stop the MySQL service process:

Command: mysqladmin-u root-p shutdown

3. Move the entire directory of / var/lib/mysql to / home/database

Command: mv / var/lib/mysql / home/database/

Through these three steps, we moved the data file of MySQL to / home/database/mysql

4. Next, we find the my.cnf configuration file

If there is no my.cnf configuration file in the / etc/ directory, find the * .cnf file under / usr/share/mysql/, copy one of them to / etc/ and rename it to my.cnf. The command is as follows:

[root@test1 mysql] # cp / usr/share/mysql/my-medium.cnf / etc/my.cnf

5. Edit the configuration file / etc/my.cnf of MySQL

Of course, to ensure that MySQL works properly, you need to specify where the mysql.sock file is generated. Modify the value to the right of the equal sign on the socket=/var/lib/mysql/mysql.sock line to: / home/mysql/mysql.sock. The specific operations are as follows:

Vi my.cnf (edit the my.cnf file with the vi tool to find the following data modification) # The MySQL server [mysqld] port=3306#socket=/var/lib/mysql/mysql.sock (the original content is to comment this line with "#" more safely) socket=/home/database/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 to change the path to the right of the equal sign in the datadir=/var/lib/mysql line to your actual storage path, that is, home/database/mysql.

[root@test1 etc] # vi / etc/init.d/mysql#datadir=/var/lib/mysql (comment this line) datadir=/home/database/mysql (plus this line).

Of course, if it is CentOS, you need to change the location of / usr/bin/mysqld_safe related files; finally, make a mysql.sock link. The command is as follows:

In-s / home/database/mysql/mysql.sock / var/lib/mysql/mysql.sock

7. Restart the MySQL service

/ etc/init.d/mysqld start, or restart Linux with the reboot command.

If you work properly, you will succeed, otherwise check again against the previous 7 steps. Also pay attention to the owner and permissions of the directory.

The detailed code is as follows:

[root@sample] # chown-R mysql:mysql / home/data/mysql/ ← changes the attribution of the database to mysql

[root@sample ~] # chmod 700 / home/data/mysql/test/ ← changes the database directory attribute to 700

[root@sample ~] # chmod 660 / home/data/mysql/test/* ← changes the attribute of the data in the database to 660

After reading the above, do you have any further understanding of how to change the path of MYSQL data storage? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report