MySQL – Moving Data Folder on Windows

When setting up MySQL on a Windows server, it is good practice to move the data folder to a secondary drive or partition. There’s a very important reason for this: you want to avoid having the database files & logs grow so large that they fill up the system drive. Follow the steps below to successfully move these files to a different location.

  1. Create the new location for the MySQL data to reside (ie. E:\MySQL\Data)
  2. Update the folder permissions on the new location to include the following (skipping this step will result in the MySQL server being unable to start after moving the data files): NETWORK SERVICE – Full Control
  3. Open Services and find the MySQL80 service – right-click it and Stop it
  4. Move all the contents from the default location: C:\ProgramData\MySQL\MySQL Server 8.0\Data to the new location
  5. Open the MySQL configuration file using NotePad++ (required for proper encoding): C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
  6. Change the datadir variable to point to the new location: datadir = "E:/MySQL/Data"
  7. Save the changes and close the file
  8. Open Services and find the MySQL80 service – right-click it and Start it
  9. Open MySQL Workbench and connect to the server to ensure the databases are accessible.

Leave a comment