Skip to main content

Transferring mysql databases to another folder or section



In some cases, it may be necessary to move the mysql database from the default directory (/ var / lib / mysql) to another directory or even to a separate partition. For example, to protect databases from damage, in case the file system on the primary partition is damaged.



The topic of creating new sections in this note will not be touched. I will describe only what needs to be done when the section for new database hosting is ready.

First you need to stop the mysql server.

  # service mysql stop 

Then copy the contents of / var / lib / mysql to the new destination. For example, this will be the / databases section.


  # cp -pR / var / lib / mysql / databases 

The -p switch saves the original file settings: owner, group, permissions, etc.

The -R switch is responsible for recursively copying directories.

The final step will be editing the mysql configuration file. Open the file /etc/my.cnf and find the variable datadir . Its default value is:


  datadir = / var / lib / mysql 

Specify the new location of the database:

  datadir = / databases / mysql 

We start mysql with the service mysql start command. Old directory can be deleted. Any errors can be found in the /var/log/daemon.log log file, or in the / var / log / syslog file.



How do you rate the article?
Звёзд: 1Звёзд: 2Звёзд: 3Звёзд: 4Звёзд: 5 ( 5 ratings, average: 4.40 out of 5)
Loading...

” Comment “ Transferring mysql databases to another folder or section

Add a comment

Your email will not be published.