ubuntu Change mysql dir

2018. 6. 12. 12:02Database/MYSQL

  1. Verify the existing MySQL installtion:From the MySQL prompt, do:You should see the current data directory:Exit the MySQL mode:
  2. exit
  3. /var/lib/mysql/
  4. select @@datadir;
  5. mysql -u root -p
  6. Stop MySQL:
  7. sudo systemctl stop mysql
  8. Verify that MySQL is stopped:
  9. sudo systemctl status mysql
  10. Copy the data to the new location:(or whatever volume you've created to store the data)
  11. sudo rsync -av /var/lib/mysql /data/newlocation
  12. Create a backup of the existing data volume
  13. sudo mv /var/lib/mysql /var/lib/mysql.bak
  14. Tell MySQL about the new location. Edit the file:and change the datadir directive, to reflect the new location:
  15. datadir=/data/newlocation
  16. /etc/mysql/mysql.conf.d/mysqld.cnf
  17. 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
  18. Then do:
  19. alias /var/lib/mysql/ -> /data/newlocation/,
  20. Create the minimal directory structure, to pass the mysql-systemd-start checks:
  21. sudo mkdir /var/lib/mysql/mysql -p
  22. Restart MySQL
  23. sudo systemctl start mysql
  24. Check status:
  25. sudo systemctl status mysql
  26. Verify that the new data directory is active:At the MySQL prompt, enter:
  27. SELECT @@datadir;
  28. mysql -u root -p
  29. Remove backup, once everything is verified to work:
  30. sudo rm -Rf /var/lib/mysql.bak
  31. Restart MySQL
  32. sudo systemctl start mysql
  33. Check status:
  34. 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