Moving MySQL Data Directory to a New Drive

Document ID : KB000010295
Last Modified Date : 14/02/2018
Show Technical Document Details
Introduction:

MySQL Data needs to be moved to a new drive because of space limitations or other reasons.

 

Note: This document is only meant to serve as a guide. For questions or more information, consult the MySQL Users Guide.

Background:

Drive with MySQL data is full and causing general database or other errors.

Environment:
All supported DevTest platforms.
Instructions:

This example moves the {{MySQL Install}}\data directory to the E:\MySQL\data directory.

The {{MySQL Install}} directory can be in multiple places depending on the Operating System and MySQL version.
For most Windows versions it will be located in a directory similar to: C:\ProgramData\MySQL\MySQL Server 5.5

  1. Shutdown DevTest and all other applications using MySQL.
  2. Shutdown the MySQL service.
  3. Copy the {{MySQL Install}}\data directory to the E:\MySQL\data directory.
  4. For backup purposes, rename the {{MySQL Install}}\data directory to {{MySQL Install}}\data-old.
  5. In the {{MySQL Install}}\my.ini file, change the datadir parameter to point to the new location, E:\MySQL\data.
  6. Permissions for new data directory:
    Match permissions for the E:\MySQL\data to {{MySQL Install}}\data.
    Another option is to give "full control" to everyone.
  7. Restart the MySQL service.
  8. Restart DevTest and other applications.
  9. After testing and confirming MySQL is operating properly, delete the {{MySQL Install}}\data-old directory and free up the hard drive space.
Additional Information:

To move the MySQL data directory to a network drive, follow the above steps with the following additions/changes:

  1. A UNC network path must be used. Symbolic links or mapped drives do not work. i.e. \\\\networksrv\\shared_data\\data  or \\\\192.168.0.2\\shared_data\\data
  2.  The account that the MySQL service runs under must have access to the network share. If not, grant access or change the account MySQL runs under.