[摘要]+---------------------------------+-------+log_bin : 用于设定是否启用二进制日志, 由此看是未开启配置文件仍然是在 /etc/my.cnf 中, ...
+---------------------------------+-------+
log_bin : 用于设定是否启用二进制日志, 由此看是未开启
配置文件仍然是在 /etc/my.cnf 中, 修改/etc/my.cnf, 增加日志文件目录:
log_bin = /tmp/mysql-bin.log
重启mysql :
bash-3.2# mysql.server start;
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/Cellar/mysql/5.7.9/data/mysql.pid).
又报错,查看错误日志,我的配置在/tmp/mysql.log
151224 00:37:34 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2015-12-23T16:37:34.643998Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-12-23T16:37:34.644124Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_pISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2015-12-23T16:37:34.644129Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2015-12-23T16:37:34.644189Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2015-12-23T16:37:34.644226Z 0 [Note] /usr/local/Cellar/mysql/5.7.9/bin/mysqld (mysqld 5.7.9-log) starting as process 24268 ...
2015-12-23T16:37:34.646468Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2015-12-23T16:37:34.646945Z 0 [ERROR] You have enabled the binary log, but you haven't provided the mandatory server-id. Please refer to the proper server start-up parameters documentation
2015-12-23T16:37:34.646978Z 0 [ERROR] Aborting
2015-12-23T16:37:34.646991Z 0 [Note] Binlog end
2015-12-23T16:37:34.647068Z 0 [Note] /usr/local/Cellar/mysql/5.7.9/bin/mysqld: Shutdown complete
151224 00:37:34 mysqld_safe mysqld from pid file /usr/local/Cellar/mysql/5.7.9/data/mysql.pid ended
重点:
You have enabled the binary log, but you haven't provided the mandatory server-id. Please refer to the proper server start-up parameters documentation
说明需要配置一个server-id, 再拿这句话百度,果然是这样。所以在 配置文件/etc/my.cn中添加 server-id = 1,再重启mysql,解决问题。而且在配置的bin-log同级目录增加了mysql-bin.000001 mysql-bin.index mysql-bin.log 三个文件,前两个是自动生成。
参数:
log_bin:设置此参数表示启用binlog功能,并指定路径名称
log_bin_index:设置此参数是指定二进制索引文件的路径与名称
binlog_do_db:此参数表示只记录指定数据库的二进制日志
binlog_ignore_db:此参数表示不记录指定的数据库的二进制日志
max_binlog_cache_size:此参数表示binlog使用的内存最大的尺寸
binlog_cache_size:此参数表示binlog使用的内存大小,可以通过状态变量binlog_cache_use和binlog_cache_disk_use来帮助测试。binlog_cache_use:使用二进制日志缓存的事务数量
binlog_cache_disk_use:使用二进制日志缓存但超过binlog_cache_size值并使用临时文件来保存事务中的语句的事务数量
max_binlog_size:Binlog最大值,最大和默认值是1GB,该设置并不能严格控制Binlog的大小,尤其是Binlog比较靠近最大值而又遇到一个比较大事务时,为了保证事务的完整性,不可能做切换日志的动作,只能将该事务的所有SQL都记录进当前日志,直到事务结束
sync_binlog:这个参数直接影响mysql的性能和完整性
sync_binlog=0:
当事务提交后,Mysql仅仅是将binlog_cache中的数据写入Binlog文件,但不执行fsync之类的磁盘 同步指令通知文件系统将缓存刷新到磁盘,而让Filesystem自行决定什么时候来做同步,这个是性能最好的。
sync_binlog=n,在进行n次事务提交以后,Mysql将执行一次fsync之类的磁盘同步指令,同志文件系统将Binlog文件缓存刷新到磁盘。
Mysql中默认的设置是sync_binlog=0,即不作任何强制性的磁盘刷新指令,这时性能是最好的,但风险也是最大的。一旦系统绷Crash,在文件系统缓存中的所有Binlog信息都会丢失
关键词:详细介绍Mysql中的4种日志