1、首先登陆mysql并查看
mysql> show variables like '%log_bin%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin | OFF |
| log_bin_basename | |
| log_bin_index | |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| sql_log_bin | ON |
+---------------------------------+-------+
6 rows in set (0.00 sec)
log_bin状态未开启
2、退出MySql
修改mysql配置文件my.cnf
添加如下两行:
server-id=1
log-bin=/var/lib/mysql/mysql-bin
保存并退出
3、重起mysql 服务
systemctl restart mysqld.service
4、登陆MySql并查看
mysql> show variables like '%log_bin%';
+---------------------------------+--------------------------------+
| Variable_name | Value |
+---------------------------------+--------------------------------+
| log_bin | ON |
| log_bin_basename | /var/lib/mysql/mysql-bin |
| log_bin_index | /var/lib/mysql/mysql-bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| sql_log_bin | ON |
+---------------------------------+--------------------------------+
此时 log_bin 状态为ON
查看 /var/lib/mysql目录,ls /var/lib/mysql
目录下有 mysql-bin.000001 和 mysql-bin.index 文件