Home > Database > Mysql Tutorial > How Can I Easily Move My MySQL Data Directory?

How Can I Easily Move My MySQL Data Directory?

DDD
Release: 2024-12-19 04:48:13
Original
563 people have browsed it

How Can I Easily Move My MySQL Data Directory?

How to Effortlessly Relocate Your MySQL Data Directory

Changing your default MySQL data directory to a more suitable location can be a necessary step for managing database space or improving performance. By following a step-by-step guide, you can seamlessly execute this change without compromising data accessibility.

Procedure:

  1. Halt MySQL:

    • Suspend MySQL services using the command:
      sudo /etc/init.d/mysql stop
  2. Data Directory Replication:

    • Duplicate your current data directory (typically located at /var/lib/mysql) to a new path:
      sudo cp -R -p /var/lib/mysql /newpath
  3. Config File Adjustment:

    • Open the MySQL configuration file:
      sudo gedit /etc/mysql/my.cnf
    • Locate the datadir entry and modify the path to the new directory.
  4. AppArmor Configuration:

    • Access the AppArmor file:
      sudo gedit /etc/apparmor.d/usr.sbin.mysqld
    • Replace instances of /var/lib/mysql with the new path.
  5. AppArmor Restart:

    • Reload AppArmor profiles:
      sudo /etc/init.d/apparmor reload
  6. MySQL Restart:

    • Reinitiate MySQL services:
      sudo /etc/init.d/mysql restart
  7. Database Access:

    • Log into MySQL to verify database accessibility.

By following these comprehensive steps, you can successfully relocate your MySQL data directory without disrupting database operations or losing any crucial information.

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template