I'm using MySQL 5.5 on a local machine to analyze a large amount of government data. I've created a local database that resides on my default drive (Win7 C: drive). I'd like to store the data on my E: drive, a large eSATA external drive.

What steps should I take?

  • cant you export the dB as a sql file, then save the file do e: then in the future if you want to restore the dB you can import this file – t q Mar 1 '12 at 19:03
  • @tq - That won't work. He wants to change the MySQL server data directory. If he exports it and imports it, it'll still be on the same drive! – Flukey Mar 1 '12 at 19:06
  1. Shutdown mysql.
  2. Move all the files in your current data directory to the new location (check out the location in step 3 - datadir parameter).
  3. Locate my.ini file (it is in the mysql installation directory). Change datadir parameter value to point to the new location.
  4. Start mysql.
| improve this answer | |
  • 1
    This gave me errors when trying to start mysql (permissions issues). I settled on the solution I post here, which I hope helps save someone some time. – snapfractalpop Aug 20 '15 at 22:38
  • 2
    @snapfractalpop question is for windows – adam Sep 8 '16 at 21:03
  • @adam windows is mentioned in the body of the question, but it is not tagged as a windows only question, nor is windows mentioned in the headline. I posted the link in the comments because it's possible other non-windows users may stumble upon this question as well. – snapfractalpop Sep 10 '16 at 3:03
  • I found I had to use / and not \ as directory separators in the directory path for datadir. I am using WAMPserver on Windows 10. – Steve Oct 16 '16 at 6:59
  • The ProgramData directory may be hidden in your file explorer. I thought it didn't exist until I changed the setting to show Hidden Files. – WestAce Feb 21 '18 at 19:00

Although you are asking for windows, here are some good directions for those ending up here looking for linux/ubuntu directions:


  • You have mysql data on an external/usb/alternate drive /mountpoint/var/lib/mysql, perhaps from a computer that died or old installation
  • You wish to move it to your new Ubuntu installation locally /var/lib/mysql
  • Stop MySQL with:
    sudo /etc/init.d/mysql stop.
  • Make a backup of the current (clean) MySQL data directory with:
    sudo cp -Rp /var/lib/mysql /var/lib/mysql.backup.
  • Then copy the old data directory from the old drive with:
    sudo cp -Rp /mountpoint/var/lib/mysql /var/lib/mysql
    where mountpoint is the path to the mount.
  • Now restart MySQL with:
    sudo /etc/init.d/mysql start

With any luck, MySQL should restart, and you should have your old databases back.

Source mb_webguy@ubuntuforums.org

| improve this answer | |
  • 4
    (!) this will not work because config is still pointing to old location – ADOConnection Jul 11 '18 at 10:50

Solution 1:

  1. First of all, backup your data using `mysqldump.
  2. If you install Mysql Server from official package, you can do it by running program MySQLINstanceConfig.exe from bin directory of your server.
  3. Import data


Second solution (not recommended, but works on same machine)

  1. Stop Mysql server.
  2. Copy data from your data directory to your new directory
  3. Open my.cnf file (In my case "C:\ProgramData\MySQL\MySQL Server 5.5\my.ini")
  4. find row like datadir="C:\ProgramData\MySQL\MySQL Server 5.5\data\" and change path to your new location
  5. Start your server

As of version 5.6 MySQLInstanceConfig.exe is no longer distributed. This functionality is being replaced by the installer. http://bugs.mysql.com/bug.php?id=66306

| improve this answer | |
  • Is there an equivalent Linux program for moving the data – Ron Piggott Feb 24 '19 at 3:09
  • After moving the data with the second approach I was not able to start MariaDB (version 5.5). After granting the service user access to the new datadir the service starts and I am bale to connect to the DB. However accessing any table still fails: [ERROR] Cannot find or open table <db>/<table> from the internal data dictionary of InnoDB though the .frm file for the table exists.. How can i ensure the permissions are set correctly? – Bram Jul 5 '19 at 8:34

For Windows, as of the MySQL Installer 1.4.6 (2015-04-07), the data location may be specified in a registry key that specifies the location of the my.ini file, so if the data was initially installed in a non-default location the my.ini file won't be in C:\ProgramData\MySQL\MySQL Server x.x\.

The location of the registry values are (at least as of MySQL 5.6):


Location is a REG_SZ that points to the folder where the MySQL application files are located; by default: C:\Program Files\MySQL\MySQL Server x.x\

DataLocation is a REG_SZ that points to the folder where my.ini is located; by default also: C:\Program Files\MySQL\MySQL Server x.x\

Also, the my.ini file path is included in the service command under this registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MySQLXX in the ImagePath REG_EXPAND_SZ value.

The default value of this string is: "C:/Program Files/MySQL/MySQL Server 5.6/bin\mysqld" --defaults-file="C:\Program Files\MySQL\MySQL Server x.x\my.ini" MySQLXX

So the bottom line is that in order to move data files in this scenario you have to follow the steps posted by @ITCuties with some additions.

Here are the full steps:

  1. Shutdown mysql.
  2. Look up the above DataLocation registry value to find the current my.ini file location, and if you are wanting to also move the my.ini file update the DataLocation path and move the my.ini file to this new path.
  3. If you are changing the location of the my.ini file, you need to update the path in the service command registry key listed above.
  4. Open the my.ini file, locate the datadir parameter. Move the files from this datadir path to the path in which you want the data to reside, and then also update the datadir parameter with this new path.
  5. Start mysql.
| improve this answer | |