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.
- Create the new location for the MySQL data to reside (ie. E:\MySQL\Data)
- 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
- Open Services and find the MySQL80 service – right-click it and Stop it
- Move all the contents from the default location: C:\ProgramData\MySQL\MySQL Server 8.0\Data to the new location
- Open the MySQL configuration file using NotePad++ (required for proper encoding): C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
- Change the datadir variable to point to the new location:
datadir = "E:/MySQL/Data"
- Save the changes and close the file
- Open Services and find the MySQL80 service – right-click it and Start it
- Open MySQL Workbench and connect to the server to ensure the databases are accessible.
Thank you for these instructions, but I think something is missing. I was able to successfully relocate my database. However, the database no longer had my primary Keys, foreign keys, unique keys, check constraints, triggers, stored procedures, or functions.
Any ideas?