vicker313 tech blog

January 14, 2010

Change MySQL Database Location in Linux

Filed under: MySQL — Tags: , — vicker313 @ 8:00 am

Install MySQL in Linux doesn’t like in Windows, either install during OS installation or install separately, you can’t define the location you want the database to be located. Steps below is to change the location of the database (or reallocate):

  1. Stop MySQL service (the service name may be different)
    service mysql stop
  2. Copy MySQL data file to destination (usually the default database directory is /var/lib/mysql. Make sure the owner of the directory and files are mysql.
    cp -r /var/lib/mysql /destination
  3. Go inside the database directory and remove the log files (usually have 2).
    rm /destination/ib_log*
  4. Locate MySQL configuration file. You can find it at /etc/my.cnf. If no such file exists, copy a sample of configuration file from /usr/share/mysql/. There will be a few files to be selected (named as my-xxx.cnf). Copy any of them to /etc and rename to my.cnf.
  5. Edit MySQL configuration file. Go to section mysqld and look for the keyword datadir (add in if not exist). Change the location to the destination.
  6. Start MySQL service and done.
    service mysql start


  1. thanks for the info, will try this out 😉

    Comment by nottyboy — March 2, 2010 @ 4:21 pm

  2. Thank You Very Much. I was able to do with your documentation.

    Comment by Srinivas — November 26, 2012 @ 2:12 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at

%d bloggers like this: