bash-3.2# tail -f /tmp/mysql.log 2015-12-23T02:22:41.467311Z 0 [Note] IPv6 is available. 2015-12-23T02:22:41.467324Z 0 [Note] - '::' resolves to '::'; 2015-12-23T02:22:41.467350Z 0 [Note] Server socket created on IP: '::'. 2015-12-23T02:22:41.584287Z 0 [Note] Event Scheduler: Loaded 0 events 2015-12-23T02:22:41.584390Z 0 [Note] /usr/local/Cellar/mysql/5.7.9/bin/mysqld: ready for connections. Version: '5.7.9' socket: '/tmp/mysql.sock' port: 3306 Homebrew 2015-12-23T02:22:42.540786Z 0 [Note] InnoDB: Buffer pool(s) load completed at 15122310:22:42 15122310:22:51 mysqld_safe A mysqld process already exists 2015-12-23T02:25:30.984395Z 2 [ERROR] Could not use /tmp/mysql_query.log for logging (error 13 - Permission denied). Turning logging off for the server process. To turn it on again: fix the cause, then either restart the query logging by using "SET GLOBAL GENERAL_LOG=ON" or restart the MySQL server. 2015-12-23T07:28:03.923562Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 61473ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.)
General Query Log
记录MySQL的日常日志,包括查询,修改,更新等的每条sql
查看MySQL是否启用了查询日志。
1 2 3 4 5 6 7 8
mysql> show global variables like "%general%"; +----------------------------------------+----------------------+ | Variable_name | Value | +----------------------------------------+----------------------+ | general_log | OFF | | general_log_file | /tmp/mysql_query.log | +----------------------------------------+----------------------+ 2 rows in set (0.00 sec)
$ 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14
15122400: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_DIVISION_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
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
mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001| 869 | +------------------+-----------+ 1 row in set (0.00 sec)
mysql> show variables like 'expire_logs_days' ; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | expire_logs_days | 0 | +------------------+-------+ 1 row in set (0.00 sec)
mysql> set global expire_logs_days=3;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'expire_logs_days' ; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | expire_logs_days | 3 | +------------------+-------+ 1 row in set (0.00 sec)