MySQL – Moving Data Directory to a Different Drive

MySQL

I'm moving data directory from D drive which has raid controller hard disk to C drive where OS installed on windows environment.

Here is the issues:

Stop Mysql server
open my.ini –> data directory -> "C drive path"
copy data directory folder to c drive folder
start mysql server

Will it work as this is innodb engines, I have heard we need to restore back as .sql files , copying raw file from one place to another doesn't work.
Is it true or do you have any other workaround as there is 600 GB data size?

Best Answer

You can try with below steps.

  1. Stop the existing MySQL instance using services.msc, shutdown must be clean so that the instance flushes any pending changes to disk.
  2. After successful instance shutdown, copy the data directory from existing location to the new location. Existing location: C:\ProgramData\MySQL\MySQL Server 5.7 New Location: E:\MySQL
  3. Change datadir parameter in current my.ini file. I have commented old entry and added new one: #datadir=C:/ProgramData/MySQL/MySQL Server 5.7\Data datadir=E:\MySQL\Data
  4. Start MySQL instance using services.msc
  5. After starting MySQL successfully, you can verify above changes by creating temporary database and verify data directory for the same database.