xiaui520 发表于 2018-10-3 10:06:32

MySQL 日志

MariaDB > SELECT * FROM courses;  
+----------+----------------+
  
| CourseID | Course         |
  
+----------+----------------+
  
|      1 | Hamo Gong      |
  
|      2 | Kuihua Baodian |
  
|      3 | Jinshe Jianfa|
  
|      4 | Taijiquan      |
  
|      5 | Daiyu Zanghua|
  
|      6 | Weituo Zhang   |
  
|      7 | Dagou Bangfa   |
  
|       12 | Nagios         |
  
|       13 | Puppet         |
  
+----------+----------------+
  
9 rows in set (0.00 sec)
  

  
MariaDB > INSERT INTO courses (Course) VALUES ('Zabbix');
  
Query OK, 1 row affected (0.00 sec)
  

  
MariaDB > SHOW BINARY LOGS;
  
+-------------------+-----------+
  
| Log_name          | File_size |
  
+-------------------+-----------+
  
| master-log.000001 |      1462 |
  
| master-log.000002 |      3375 |
  
+-------------------+-----------+
  
2 rows in set (0.00 sec)
  

  
MariaDB > DELETE FROM courses WHERE CourseID=13;
  
Query OK, 1 row affected (0.04 sec)
  

  
MariaDB > SELECT * FROM courses;
  
+----------+----------------+
  
| CourseID | Course         |
  
+----------+----------------+
  
|      1 | Hamo Gong      |
  
|      2 | Kuihua Baodian |
  
|      3 | Jinshe Jianfa|
  
|      4 | Taijiquan      |
  
|      5 | Daiyu Zanghua|
  
|      6 | Weituo Zhang   |
  
|      7 | Dagou Bangfa   |
  
|       12 | Nagios         |
  
|       14 | Zabbix         |
  
+----------+----------------+
  
9 rows in set (0.00 sec)
  

  
MariaDB > SHOW BINARY LOGS;
  
+-------------------+-----------+
  
| Log_name          | File_size |
  
+-------------------+-----------+
  
| master-log.000001 |      1462 |
  
| master-log.000002 |      4993 |
  
+-------------------+-----------+
  
2 rows in set (0.00 sec)
  

  
# 查看当前正在使用的二进制日志文件
  
MariaDB > SHOW MASTER STATUS;
  
+-------------------+----------+--------------+------------------+
  
| File            | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  
+-------------------+----------+--------------+------------------+
  
| master-log.000002 |   4493 |            |                  |
  
+-------------------+----------+--------------+------------------+
  
1 row in set (0.00 sec)
  

  
# 查看记录的信息,可以发现只是记录了跟数据发生改变相关的语句,查询语句SELECT不记录;
  
MariaDB > SHOW BINLOG EVENTS IN 'master-log.000002';
  
+-------------------+------+-------------+-----------+-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  
| Log_name          | Pos| Event_type| Server_id | End_log_pos | Info                                                                                                                                                                                                                                                                        |
  
+-------------------+------+-------------+-----------+-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  
| master-log.000002 |    4 | Format_desc |         1 |         245 | Server ver: 5.5.44-MariaDB-log, Binlog ver: 4                                                                                                                                                                                                                                 |
  
| master-log.000002 | 3236 | Query       |         1 |      3348 | use `hellodb`; INSERT INTO courses (Course) VALUES ('Zabbix')                                                                                                                                                                                                               |
  
| master-log.000002 | 3348 | Xid         |         1 |      3375 | COMMIT /* xid=45 */                                                                                                                                                                                                                                                         |
  
| master-log.000002 | 3797 | Query       |         1 |      4094 | use `Syslog`; insert into SystemEvents (Message, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('Starting Session 45 of user root.', 3, 'centos7', 6, '20161201145001', '20161201145001', 1, 'systemd:')                        |
  
| master-log.000002 | 4094 | Xid         |         1 |      4121 | COMMIT /* xid=48 */                                                                                                                                                                                                                                                         |
  
| master-log.000002 | 4121 | Query       |         1 |      4191 | BEGIN                                                                                                                                                                                                                                                                         |
  
| master-log.000002 | 4191 | Intvar      |         1 |      4219 | INSERT_ID=6790                                                                                                                                                                                                                                                                |
  
| master-log.000002 | 4219 | Query       |         1 |      4521 | use `Syslog`; insert into SystemEvents (Message, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('(root) CMD (/usr/lib64/sa/sa1 1 1)', 9, 'centos7', 6, '20161201145001', '20161201145001', 1, 'CROND:')                   |
  
| master-log.000002 | 4521 | Xid         |         1 |      4548 | COMMIT /* xid=52 */                                                                                                                                                                                                                                                         |
  
| master-log.000002 | 4548 | Query       |         1 |      4619 | BEGIN                                                                                                                                                                                                                                                                         |
  
| master-log.000002 | 4619 | Query       |         1 |      4720 | use `hellodb`; DELETE FROM courses WHERE Course=13                                                                                                                                                                                                                            |
  
| master-log.000002 | 4720 | Query       |         1 |      4792 | COMMIT                                                                                                                                                                                                                                                                        |
  
| master-log.000002 | 4792 | Query       |         1 |      4863 | BEGIN                                                                                                                                                                                                                                                                         |
  
| master-log.000002 | 4863 | Query       |         1 |      4966 | use `hellodb`; DELETE FROM courses WHERE CourseID=13                                                                                                                                                                                                                        |
  
| master-log.000002 | 4966 | Xid         |         1 |      4993 | COMMIT /* xid=57 */                                                                                                                                                                                                                                                         |
  
+-------------------+------+-------------+-----------+-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  

  
# 显示事件从指定的地方开始
  
MariaDB > SHOW BINLOG EVENTS IN 'master-log.000002' FROM 9191;
  
+-------------------+------+------------+-----------+-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  
| Log_name          | Pos| Event_type | Server_id | End_log_pos | Info                                                                                                                                                                                                                                                      |
  
+-------------------+------+------------+-----------+-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  
| master-log.000002 | 9191 | Intvar   |         1 |      9219 | INSERT_ID=6802                                                                                                                                                                                                                                              |
  
| master-log.000002 | 9219 | Query      |         1 |      9516 | use `Syslog`; insert into SystemEvents (Message, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('Starting Session 48 of user root.', 3, 'centos7', 6, '20161201151001', '20161201151001', 1, 'systemd:')      |
  
| master-log.000002 | 9516 | Xid      |         1 |      9543 | COMMIT /* xid=96 */                                                                                                                                                                                                                                       |
  
| master-log.000002 | 9543 | Query      |         1 |      9613 | BEGIN                                                                                                                                                                                                                                                       |
  
| master-log.000002 | 9613 | Intvar   |         1 |      9641 | INSERT_ID=6803                                                                                                                                                                                                                                              |
  
| master-log.000002 | 9641 | Query      |         1 |      9943 | use `Syslog`; insert into SystemEvents (Message, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('(root) CMD (/usr/lib64/sa/sa1 1 1)', 9, 'centos7', 6, '20161201151001', '20161201151001', 1, 'CROND:') |
  
| master-log.000002 | 9943 | Xid      |         1 |      9970 | COMMIT /* xid=100 */                                                                                                                                                                                                                                        |
  
+-------------------+------+------------+-----------+-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  
7 rows in set (0.00 sec)
  

  
# 限制显示的行数
  
MariaDB > SHOW BINLOG EVENTS IN 'master-log.000002' FROM 9191 LIMIT 3;
  
+-------------------+------+------------+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  
| Log_name          | Pos| Event_type | Server_id | End_log_pos | Info                                                                                                                                                                                                                                                   |
  
+-------------------+------+------------+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  
| master-log.000002 | 9191 | Intvar   |         1 |      9219 | INSERT_ID=6802                                                                                                                                                                                                                                       |
  
| master-log.000002 | 9219 | Query      |         1 |      9516 | use `Syslog`; insert into SystemEvents (Message, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('Starting Session 48 of user root.', 3, 'centos7', 6, '20161201151001', '20161201151001', 1, 'systemd:') |
  
| master-log.000002 | 9516 | Xid      |         1 |      9543 | COMMIT /* xid=96 */                                                                                                                                                                                                                                    |
  
+-------------------+------+------------+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  
3 rows in set (0.00 sec)


页: [1]
查看完整版本: MySQL 日志