MySQL 5.7在Ubuntu 18.04上移动数据文件目录DATADIR

注意由于apparmor的存在,以及mysql-systemd-start脚本的影响,导致在Ubuntu上移动MYSQL DATADIR有一些小问题。

 


步骤0 创建目标目录; 移动数据文件目录,常见的原因有 移动数据到新磁盘或逻辑卷等


例如目标目录路径是 /m01/mysql

mkdir -p /m01/mysql
chown mysql:mysql /m01
chown mysql:mysql /m01/mysql






步骤1 确认datadir

su - root 

mysql -u root -p

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


关闭MYSQL实例守护进程

systemctl stop mysql

确认状态

systemctl status mysql




步骤2 同步数据文件到新目录 


rsync -av /var/lib/mysql /m01


将原目录归档为备份

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



步骤3 对/etc/mysql/mysql.conf.d/mysqld.cnf参数文件修改datadir 参数 


vi /etc/mysql/mysql.conf.d/mysqld.cnf

修改datadir参数为

datadir         = /m01/mysql



步骤4 禁用apparmor 的mysql profile



aa-status |grep mysql
ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld



重启 apparmor

 systemctl restart apparmor

aa-status |grep mysql

//aa-status |grep mysql 应当无结果


步骤5  针对mysql-systemd-start中的默认路径问题 创建原目录 

mkdir /var/lib/mysql/mysql -p


步骤6 重启mysql实例

systemctl start mysql
systemctl status mysql

mysql -u root -p

确认datadir

select @@datadir;

 

 


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *