Move the MySQL data files
If the drive the data is currently stored on is running out of room and you have another drive with lots of room - you might want to move there.
Step-by-step guide
The process isn't too hard but does require stopping and restarting the MySQL database service.
Locate your my.ini file
Example: C:\ProgramData\MySQL\MySQL Server 5.6
In the my.ini file find the datadir and then locate the current directory
Usually defaults to: C:/ProgramData/MySQL/MySQL Server 5.6/data
Create a new destination folder for the MySQL Data
If NOT using the XCopy variation which I recommend then you need to manually set some permissions
Verify permissions are the same on the old and the new directory
Be sure that NETWORK SERVICE has full permissions (the owner of the service as of MySQL 5.6)
Before V5.6 it was owned by SYSTEM which already had full permissions on ALL folders
Change the datadir value to the name of the new location
end the new location path with a slash /
This doesn’t seem to be needed in MySQL
Save the my.ini
DO NOT save your edits with NOTEPAD. It often corrupts the file though it might look okay. Using Notepad++ in Administrator mode is recommended.
Stop the MySQL service
Copy all the data files to the new location - use the xcopy command below is quite easy
include the ibdata* and ib_logfile* files (required for INNODB type tables)
Restart the MySQL service
Variation- Use XCopy
The use of xcopy
allows the permissions to be copied as well.
Be sure to run the xcopy command in a cmd window using run as Administrator to avoid a permission denied error.
xcopy "C:\ProgramData\MySQL\MySQL Server 8.0\Data" "D:\MySQL\Data" /E /H /K /O /X
Why not simply copy? Well because that's not COOL!, this helps you not lose permissions on the copied folder, so that when you restart
MySQL80
, it won't give a stupid error: "The MySQL80 service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs." - Courtesy:Microsoft
There are few ways to stop/start the MySQL service
MySQL Workbench - Management - Instance - Startup/Shutdown
MySQL Task Tray icon if installed
Server - Services - MySQL56 - stop/start directly here