Mysql 数据库日志与数据文件分开

时间:2022-11-14 14:29:02

参考:
https://blog.csdn.net/jiao_fuyou/article/details/78366621

myql默认配置情况下,二进制日志文件是保存在默认的数据目录 data 下,如:/usr/local/mysql/data。
有时我们希望把 binlog 修改保存到其他目录下,现记录下操作过程。
假设原目录为: /usr/local/mysql/data,并且已有一些日志文件 mysql-bin.??????
新目录为: /var/log/mysql/

1. 停止数据库
systemctl stop mysqld.service

2. 修改日志存放路径:

vi /etc/my.cnf
修改 log-bin=mysql-bin 为 log-bin=/var/log/mysql/mysql-bin

mkdir -p /var/log/mysql/
chown -R mysql /var/log/mysql/
chgrp -R mysql /var/log/mysql/

cp /var/lib/mysql/mysql-bin.* /var/log/mysql/

3. 修改新路径

vi /var/log/mysql/mysql-bin.index
把每一行的文件路径改为新目录的绝对路径
即 ./mysql-bin.?????? 改为/var/log/mysql/mysql-bin.??????

/var/log/mysql/mysql-bin.000001
/var/log/mysql/mysql-bin.000002
/var/log/mysql/mysql-bin.000003
/var/log/mysql/mysql-bin.000004
/var/log/mysql/mysql-bin.000005
/var/log/mysql/mysql-bin.000006
/var/log/mysql/mysql-bin.000007
/var/log/mysql/mysql-bin.000008
/var/log/mysql/mysql-bin.000009
/var/log/mysql/mysql-bin.000010
/var/log/mysql/mysql-bin.000011
/var/log/mysql/mysql-bin.000012

4.启动数据库
mysql.server start