mysql 启动log_bin日志模式

1.准备工作

登录数据库查看log_bin参数

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   |
+---------------------------------+-------+
5 rows in set (0.01 sec)

可以看到所有log_bin相关的状态都是off

2. 配置my.cnf

  打开/etc/my.cnf 在日志部分更新如下字段

# LOGGING #
log-error                      = /usr/local/mysql/data/mysql-error.log
server-id=1
log-bin=mysql-bin

主要增加server-id和log-bin字段。

然后重启mysql

/etc/init.d/mysqld restart

输入1.中的指令就可以 看到log_bin状态

mysql>  show variables like 'log_bin%';
+---------------------------------+---------------------------------------+
| Variable_name                   | Value                                 |
+---------------------------------+---------------------------------------+
| log_bin                         | ON                                    |
| log_bin_basename                | /usr/local/mysql/data/mysql-bin       |
| log_bin_index                   | /usr/local/mysql/data/mysql-bin.index |
| log_bin_trust_function_creators | OFF                                   |
| log_bin_use_v1_row_events       | OFF                                   |
+---------------------------------+---------------------------------------+
5 rows in set (0.01 sec)

然后在/usr/local/mysql/data目录下应该会有mysql-bin.000001 这种文件 这些就记录了数据库的变动

你可能感兴趣的:(基础知识)