1. 程式人生 > >Change data directory for MySQL

Change data directory for MySQL

In fact, usually MySQL installed by default configuration and the size of default storage on cloud is limited. If you want to use cloud as database server then you must increment available size storage for it. Suppose you mounted 1TB to path “/u01/database” and you want to change path default, we have 2 solutions for this problem

Solution 1: Copy all data default to “/u01/database”  and change in config file

Step 1 : show default config with command

vim /etc/my.cnf

datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock collation-server = utf8_unicode_ci character-set-server = utf8 init-connect ='SET NAMES utf8' symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid

Step 2 : Stop service

service mysqld stop

Step 3 : Copy to backup data

cp -r /var/lib/mysql /var/lib/backup/mysql

Step 4 : Move data to new path

mv /var/lib/mysql /u01/database

Step 5 : Grant permission read/write folder for user mysql

chown -R mysql:mysql /data

Step 6 : Restart service

service mysqld restart

Solution 2

: Use soft link synchronize data (Simple and easy )

Step 1 : Stop MySQL

service mysqld stop

Step 2 : synchronize path

rsync -av /var/lib/mysql /u01/database

Step 3 : Move old path to backup

mv /var/lib/mysql /var/lib/mysql.bak

Step 4 : Restart

service mysqld restart

done !

Advertisements

Like this:

Like Loading...