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 location of MySQL database directory under Linux (CentOS) system

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article is about how to change the location of the MySQL database directory under Linux (CentOS) system. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

How to change the location of MySQL database directory under CentOS system

1. First of all, we need to close MySQL with the following command:

Service mysqld stop

2. Then transfer the data. For security, we use the replicated command cp to find the original directory of mysql.

Cd / var/libls

After running this command, you will see the directory of mysql, and then execute the cp command

Cp-a mysql / home/mysql_data/

So the database is copied to / home/mysql_data.

Note: (- a) this parameter must be taken, otherwise the permissions copied in the past will be incorrect. )

If the database is relatively large, the time will be relatively long, and it may time out. How to set up the method that ssh does not time out, please find the relevant information by yourself.

3. Then we modify the configuration file. There are a total of three. I will explain them one by one below:

Modify the first file: back up before modification

Cp / etc/my.cnf / etc/my.cnfbakvi / etc/my.cnf

Change the directory of datadir to / home/mysql_data/mysql after opening it.

Change socket to / home/mysql_data/mysql/mysql.sock. For security reasons, you can delete the original comment, then add a new line and change it to the current directory.

Modify the second file: back up before modification

Cp / etc/init.d/mysqld / etc/init.d/mysqldbakvi / etc/init.d/mysqld

Note: the exact location is / etc/rc.d/init.d/mysqld, because there is a / etc/init.d to / etc/rc.d/init.d mapping here.

So it's easy to use the above command.

Change the path to the right of the equal sign in the datadir=/var/lib/mysql line to your current actual storage path: / home/mysql_data/mysql

Modify the third file: back up before modification

Cp / usr/bin/mysqld_safe / usr/bin/mysqld_safebakvi / usr/bin/mysqld_safe

Here, also change the directory of datadir to / home/mysql_data/mysql

4. Below, you need to establish a link to mysql.sock:

Ln-s / home/mysql_data/mysql/mysql.sock / var/lib/mysql/mysql.sock

Now that all the changes have been completed, start mysql

Service mysqld start

Or restart linux

Reboot

Check to see if Mysql is working properly, and if it starts up properly, there will be basically no problem.

Thank you for reading! On "how to change the MySQL database directory location under the Linux (CentOS) system" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

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

Database

Wechat

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

12
Report