MySQL: changing the storage location for databases

WEBBY STUFF Add comments

By default when you install MySQL it stores databases on the C drive, you can change this during installation but perhaps you forgot to change the data files path during installation or completely missed the option to do this, or perhaps you used the Web Platform Installer which doesn't give you any option to change the data files path.

On windows 2008 the datadir is “C:\ProgramData\MySQL\MySQL Server 5.5\data”

This is generally not the best idea as your c drive should be only for the OS and installed programs, you should put all your data on a different drive and keep it separate from the OS. So if you find yourself needing to change this after installation, here is how.

Open your my.ini file

On windows 2008 this is in C:\ProgramData\MySQL\MySQL Server 5.5\”

On other windows version just look at the mysql service properties to find out where the defaults-file is.

mysql-service

now find the “datadir” parameter and change it to where you want to store your databases.

E.G.
datadir="D:\MySQL\data\"

Now STOP the MySQL service.

Now you must copy the original data directory to the new location.

E.G.
copy “C:\ProgramData\MySQL\MySQL Server 5.5\data” to “D:\mysql\data”

now restart MySQL.

If the service fails to start, double check that you have entered the path correctly in my.ini and that the path exists, and that all the data files have copied across properly.

Check your new data folder permissions and make sure it has “NETWORK SERVICE” with full permissions. On Windows 2008 these permissions may not exist by default.

mysql_data_dir_permissions

1 response to “MySQL: changing the storage location for databases”

  1. Richard Herbert Says:
    Actually the MySQL 5.5 installer gives you the option to choose the location of your data files.

    Select the "Server data files" feature and click the "Browse..." to choose a different location...

    https://twitter.com/richardherbert/status/291928202757173252/photo/1

Leave a Reply

Leave this field empty

Powered by Mango Blog. Design and Icons by N.Design Studio