ubuntu Change mysql dir
2018. 6. 12. 12:02ㆍDatabase/MYSQL
- Verify the existing MySQL installtion:From the MySQL prompt, do:You should see the current data directory:Exit the MySQL mode:
exit
/var/lib/mysql/
select @@datadir;
mysql -u root -p
- Stop MySQL:
sudo systemctl stop mysql
- Verify that MySQL is stopped:
sudo systemctl status mysql
- Copy the data to the new location:(or whatever volume you've created to store the data)
sudo rsync -av /var/lib/mysql /data/newlocation
- Create a backup of the existing data volume
sudo mv /var/lib/mysql /var/lib/mysql.bak
- Tell MySQL about the new location. Edit the file:and change the
datadir
directive, to reflect the new location: datadir=/data/newlocation
/etc/mysql/mysql.conf.d/mysqld.cnf
- Tell AppArmor about it: edit the file
/etc/apparmor.d/tunables/alias
and add:to the bottom of that file (the comma at the end of the line is NOT a typo).sudo systemctl restart apparmor
- Then do:
alias /var/lib/mysql/ -> /data/newlocation/,
- Create the minimal directory structure, to pass the
mysql-systemd-start
checks: sudo mkdir /var/lib/mysql/mysql -p
- Restart MySQL
sudo systemctl start mysql
- Check status:
sudo systemctl status mysql
- Verify that the new data directory is active:At the MySQL prompt, enter:
SELECT @@datadir;
mysql -u root -p
- Remove backup, once everything is verified to work:
sudo rm -Rf /var/lib/mysql.bak
- Restart MySQL
sudo systemctl start mysql
- Check status:
sudo systemctl status mysql
'Database > MYSQL' 카테고리의 다른 글
MySQL 잔존율 쿼리 (SP & Query) (0) | 2022.08.30 |
---|---|
[MySQL] Dummy Table 만들기 (0) | 2021.10.29 |
GEOIP Update (0) | 2018.01.03 |