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):
- Stop MySQL service (the service name may be different)
service mysql stop
- 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
- Go inside the database directory and remove the log files (usually have 2).
- 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.
- 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.
- Start MySQL service and done.
service mysql start