Skip to content

Moving MySQL databases/files to another drive

Do you ever wonder where does your database lives? MySQL is just like any other programs, it runs and listens to specified port, accepts connections, analyzes commands and performs action which is querying to databases. Now we wonder where does this database lives? How do they look like? What are they? This database are just files in their own type and format. In a normal MySQL installation, they usually located in

directory. Note that it varies the installation path, but whatever you installation path will be and whatever MySQL version you used, the directory of the databases are usually in “data” folder or “datadir” folder under MySQL folder. Now that we know where this databases are located, we can safely move them in a new location if needed. Example scenario when you are organizing things and you want your development or work space to move to another drive, say drive E. In this case, below are steps on what to do:

For Windows:

  1. Stop your MySQL Server
  2. Copy the files on “data” directory to new location
  3. Locate the my.ini file. This is the main MySQL configuration file. This is usually just on the MySQL folder installation.
  4. Open it with admin permission and find the line “datadir= “whatever/your/path/to/data”, update this to your new “data” folder location.
  5. Start you MySQL Server
  6. Done.

That’s it! You have now moved you databases on the new drive.

For Linux users:

  1. SSH to your MySQL server
  2. Make sure to make a backup first!
  3. Lets now move to its new mount or location
  4. Lastly, open the mysql config file, usually located in


    and update the “datadir” location path to point to your new location.
  5. Start you the MySQL server
  6. Done.

That’s it. You are now able to move your MySQL databases file safely.

Published indatabasesservers

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *