Home >Database >Mysql Tutorial >Can I Move My MySQL Data Directory Without Affecting Database Access?

Can I Move My MySQL Data Directory Without Affecting Database Access?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-12 19:02:20204browse

Can I Move My MySQL Data Directory Without Affecting Database Access?

Changing the Default MySQL Data Directory

Is it feasible to move your MySQL data directory to a different location while still accessing databases from their previous location? Here's a step-by-step guide:

Procedure:

  1. Suspend MySQL with: sudo /etc/init.d/mysql stop
  2. Replicate the present data directory: sudo cp -R -p /var/lib/mysql /newpath
  3. Adjust the MySQL configuration file: sudo gedit /etc/mysql/my.cnf and modify the datadir entry.
  4. Alter /etc/apparmor.d/usr.sbin.mysqld, updating /var/lib/mysql references to the new path.
  5. Reload AppArmor profiles: sudo /etc/init.d/apparmor reload
  6. Restart MySQL: sudo /etc/init.d/mysql restart

Accessing Databases from the Old Location:

Once MySQL is restarted, you can access databases from either the original or new location. The data directory has been relocated, but the databases remain accessible from their former location.

The above is the detailed content of Can I Move My MySQL Data Directory Without Affecting Database Access?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn