MySQL - How to change data directory

Updated on December 8th, 2022

Table of Contents

X

Symptom

Sometimes there is a requirement to change the save location of MySQL, including logs, etc. This could be due to a drive running out of space.

Resolution

  1. Shut down the MySQL service.
  2. Move all the files in your current Data directory to the new location (listed in step 3 - datadir parameter).mceclip1.pngmceclip2.png
  3. Locate the my.ini file (this is found in the mysql installation directory - as shown in the image above). Change the datadir parameter value to point to the new location. Save the file.mceclip0.png
  4. Start MySQL.

Tip: If the service won't start, make sure that the drive has write permissions enabled for the user. The error looks like this:

mceclip0.png


Was this article helpful?