ubuntu-16.04更改mysql默认数据存储目录

登录mysql查看当前数据存储目录

mysql -uroot -p

mysql> select @@datadir;
+-----------------+
| @@datadir       |
+-----------------+
| /var/lib/mysql/ |
+-----------------+
1 row in set (0.00 sec)

关闭mysql-server

sudo systemctl stop mysql

确认的确关闭mysql-server

sudo systemctl status mysql
  • 关闭无误,输出类似 “Jul 18 11:24:20 ubuntu-512mb-nyc1-01 systemd[1]: Stopped MySQL Community Server.”

转移数据目录

sudo rsync -av /var/lib/mysql /data/

备份源数据

sudo mv /var/lib/mysql /var/lib/mysql.bak
sudo mkdir /var/lib/mysql/mysql -p
  • sudo mkdir /var/lib/mysql/mysql -p 是为了保证 /usr/share/mysql/mysql-systemd-start 中验证目录正确

修改mysql-server配置 /etc/mysql/mysql.conf.d/mysqld.cnf

datadir=/data/mysql

AppArmor权限修改 追加以下内容到 /etc/apparmor.d/tunables/alias

alias /var/lib/mysql/ -> /data/mysql/,

重启AppArmor

sudo systemctl restart apparmor
  • 没有追加alias内容,可能导致

<pre>
Job for mysql.service failed because the control process exited with error code. See “systemctl status mysql.service”
and “journalctl -xe” for details.
</pre>

启动mysql-server

sudo systemctl start mysql
sudo systemctl status mysql

原文链接
https://www.digitalocean.com/…

欢迎您加入我们的专属QQ讨论群组① 233415606 ② 233415756

    原文作者:xingqiba
    原文地址: https://segmentfault.com/a/1190000008645395
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞