mysql日志类型简介mysql的日志大概可以分成三种,错误日志(error_log),查询日志(query_log),二进制日志(binary_log):
查询日志(query log):一般的,查询日志可以分为两种,通用查询日志(general query log)和慢查询日志(slow query log);其中,通用查询日志可以用来各客户端连接时的相关信息和在数据库上执行的sql语句;慢查询日志记录了sql语句时间超过了预设的long_query_time的语句,在数据量较大的情况下,可以看看慢查询日志中有哪些语句需要进行优化。
二进制日志(binary_log):简单来说,二进制日志记录了对mysql更新的操作,主要目的是尽可能的将数据库恢复到数据库故障点,因为二进制日志包含备份后进行的所有更新。
三种日志各有不同的作用,同时也需要不同的方法进行配置,这里先讲普通的error log的配置方法,其它两种日后补充。
error_log相似与oracle中的alert,mysql的error log用于记录错误信息的log,但error记录的不仅仅是错误信息,有关服务进程的错误信息也会被记录(critical级别);如果mysqld进程发现某些表需要自动检查或者修复的话,也会抛出相关信息到该log。
配置方法1、找到配置文件/etc/my.cnf,如果找不到find / -type f -name 'my.cnf'全局查找即可
2、将错误日志参数写入配置文件
[mysqld_safe]log-error=/var/lib/mysql/mysql.err
3、另一种方法
mysql在命令行启动时,可以添加日志的加载参数--log-output,其中--log-output还有三种可选参数来制定日志文件输出方式:
- table:将日志记录至数据库表中
- file:将日志记录在文件中
- none:不记录
举例启用错误日志,并记录日志文件到数据库表和日志文件中:
--log-output=table,file --error_log
启用慢查询日志和普通查询日志,并将它们的日志记录在表中:--log-output=table --general_log --slow_query_log
启用慢查询日志,记录到日志文件中,并制定输出路径:--log-output=file --slow_query_log --slow_query_log_file=/var/lib/mysql/- mysql_slow.log
设置成功后,进入查看:
mysql> show variables like 'log_error';
+---------------+---------------------+| variable_name | value |
+---------------+---------------------+| log_error | /var/log/mysqld.log |
+---------------+---------------------+1 row in set (0.00 sec)
[root@localhost mysql]# tailf /var/log/mysqld.log
2017-08-07t12:32:54.258884z 0 [note] ipv6 is available.
2017-08-07t12:32:54.258892z 0 [note] - '::' resolves to '::';
2017-08-07t12:32:54.258908z 0 [note] server socket created on ip: '::'.
2017-08-07t12:32:54.259622z 0 [note] innodb: loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2017-08-07t12:32:54.260814z 0 [note] innodb: buffer pool(s) load completed at 170807 8:32:54
2017-08-07t12:32:54.266749z 0 [note] /usr/sbin/mysqld: ready for connections.
version: '5.7.19' socket: '/var/lib/mysql/mysql.sock' port: 3306 mysql community server (gpl)
2017-08-07t12:32:54.266772z 0 [note] executing 'select * from information_schema.tables;' to get a list of tables using the deprecated partition engine. you may use the startup option '--disable-partition-engine-check' to skip this check.
2017-08-07t12:32:54.266774z 0 [note] beginning of list of non-natively partitioned tables
2017-08-07t12:32:54.318211z 0 [note] end of list of non-natively partitioned tables
以上就是mysql中error_log介绍的详细内容。