Change MySQL Data directory location in Windows

Step 1:

Stop the existing MySQL instance using services.msc, shutdown must be clean so that the instance flushes any pending changes to disk.

MySQL - Services.msc

MySQL – Services.msc

MySQL - Services.msc - stop

MySQL – Services.msc – stop

MySQL - Services.msc - stopped

MySQL – Services.msc – stopped

Step 2:

After successful instance shutdown, copy the data directory from existing location to the new location, in my case:

Existing location: C:\ProgramData\MySQL\MySQL Server 5.7

New Location: E:\MySQL

Step 3:

Change datadir parameter in current my.ini file. I have commented old entry and added new one:

MySQL - my.ini

MySQL – my.ini

# Path to the database root
#datadir=C:/ProgramData/MySQL/MySQL Server 5.7\Data
datadir=E:\MySQL\Data

Step 4:

Start MySQL instance using services.msc

MySQL - Services.msc - start

MySQL – Services.msc – start

MySQL - Services.msc - started

MySQL – Services.msc – started

Step 5:

After starting MySQL successfully, you can verify above changes by creating demo database and verify data dirctory for the same database. Test database: Myslott

MySQL - create database through workbench

MySQL – create database through workbench

MySQL - Data Directory

MySQL – Data Directory

Database Created successfully and myslott directory also created under new data directory.

Cheers!!

Stay Tune. 🙂

2 thoughts on “Change MySQL Data directory location in Windows

  1. it seems that if you follow the above way, and finally when you start the mysql service, it still uses the previous my.ini file not the new my.ini which only copied in different location

  2. still generates error Some services stopped automatically. However I set Network SERVICE permission to new drive

Leave a Reply

%d bloggers like this: