{"id":204242,"date":"2020-11-09T08:11:46","date_gmt":"2020-11-09T00:11:46","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=204242"},"modified":"2020-10-29T15:13:06","modified_gmt":"2020-10-29T07:13:06","slug":"mysql-operation-records","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/mysql-operation-records.html","title":{"rendered":"mysql\u67e5\u770b\u6570\u636e\u5e93\u64cd\u4f5c\u8bb0\u5f55"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nMySQL\u7684\u67e5\u8be2\u65e5\u5fd7\u8bb0\u5f55\u4e86\u6240\u6709MySQL\u6570\u636e\u5e93\u8bf7\u6c42\u7684\u4fe1\u606f\u3002\u65e0\u8bba\u8fd9\u4e9b\u8bf7\u6c42\u662f\u5426\u5f97\u5230\u4e86\u6b63\u786e\u7684\u6267\u884c\u3002\u9ed8\u8ba4\u6587\u4ef6\u540d\u4e3ahostname.log\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0bMySQL\u67e5\u8be2\u65e5\u5fd7\u662f\u5173\u95ed\u7684\u3002\u751f\u4ea7\u73af\u5883\uff0c\u5982\u679c\u5f00\u542fMySQL\u67e5\u8be2\u65e5\u5fd7\uff0c\u5bf9\u6027\u80fd\u8fd8\u662f\u6709\u86ee\u5927\u7684\u5f71\u54cd\u7684\u3002\u53e6\u5916\u5f88\u591a\u65f6\u5019\uff0cMySQL\u6162\u67e5\u8be2\u65e5\u5fd7\u57fa\u672c\u53ef\u4ee5\u5b9a\u4f4d\u90a3\u4e9b\u51fa\u73b0\u6027\u80fd\u95ee\u9898\u7684SQL\uff0c\u6240\u4ee5MySQL\u67e5\u8be2\u65e5\u5fd7\u5e94\u7528\u7684\u573a\u666f\u5176\u5b9e\u4e0d\u591a\uff0c\u6709\u70b9\u9e21\u808b\u7684\u611f\u89c9\uff0c\u5b83\u8ddfSQL Server\u4e2d\u7684profiler\u6709\u70b9\u7c7b\u4f3c\uff0c\u4f46\u662f\u8fd9\u4e2a\u4e0d\u80fd\u8ddf\u8e2a\u67d0\u4e2a\u4f1a\u8bdd\u3001\u7528\u6237\u3001\u5ba2\u6237\u7aef\u3002\u5b83\u53ea\u80fd\u5bf9\u6574\u4e2a\u6570\u636e\u5e93\u8fdb\u884c\u8ddf\u8e2a\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
window \u73af\u5883\u4e0b<\/strong><\/div>\n

\u627e\u5230my.ini,\u5728\u4e0b\u9762\u6dfb\u52a0\uff1a
\nlog=\u5b58\u653e\u65e5\u5fd7\u7684\u8def\u5f84\/my.log
\n\u4fdd\u5b58\u6587\u4ef6\uff0c\u91cd\u542fmysql\u670d\u52a1\uff0c\u4e4b\u540e\u5c31\u53ef\u4ee5\u5728\u5bf9\u5e94\u76ee\u5f55\u7684\u4e0b\u627e\u5230my.log\u6587\u4ef6\u3002<\/p>\n

linux\u73af\u5883\u4e0b<\/strong><\/div>\n

MySQL\u4e2d\u7684\u53c2\u6570general_log\u7528\u6765\u63a7\u5236\u5f00\u542f\u3001\u5173\u95edMySQL\u67e5\u8be2\u65e5\u5fd7,\u53c2\u6570general_log_file\u7528\u6765\u63a7\u5236\u67e5\u8be2\u65e5\u5fd7\u7684\u4f4d\u7f6e\u3002\u6240\u4ee5\u5982\u679c\u4f60\u8981\u5224\u65adMySQL\u6570\u636e\u5e93\u662f\u5426\u5f00\u542f\u4e86\u67e5\u8be2\u65e5\u5fd7\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u3002general_log\u4e3aON\u8868\u793a\u5f00\u542f\u67e5\u8be2\u65e5\u5fd7\uff0cOFF\u8868\u793a\u5173\u95ed\u67e5\u8be2\u65e5\u5fd7\u3002<\/p>\n

\r\nmysql> show variables like '%general_log%';\r\n+------------------+------------------------------+\r\n| Variable_name    | Value                        |\r\n+------------------+------------------------------+\r\n| general_log      | OFF                          |\r\n| general_log_file | \/var\/lib\/mysql\/DB-Server.log |\r\n+------------------+------------------------------+\r\n2 rows in set (0.00 sec)\r\n<\/pre>\n

\u53e6\u5916\uff0cMySQL\u7684\u67e5\u8be2\u65e5\u5fd7\u652f\u6301\u5199\u5165\u6587\u4ef6\u6216\u5199\u5165\u6570\u636e\u8868\u4e24\u79cd\u5f62\u5f0f\uff0c\u8fd9\u4e2a\u7531\u53c2\u6570log_output\u63a7\u5236\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

\r\nmysql> show variables like 'log_output';\r\n+---------------+-------+\r\n| Variable_name | Value |\r\n+---------------+-------+\r\n| log_output    | FILE  |\r\n+---------------+-------+\r\n1 row in set (0.00 sec)\r\n \r\n<\/pre>\n
\u5f00\u542fMySQL\u67e5\u8be2\u65e5\u5fd7<\/strong><\/span><\/div>\n
\r\nmysql> set global general_log = on;\r\nQuery OK, 0 rows affected (0.11 sec)\r\n \r\nmysql> show variables like 'general_log';\r\n+---------------+-------+\r\n| Variable_name | Value |\r\n+---------------+-------+\r\n| general_log   | ON    |\r\n+---------------+-------+\r\n1 row in set (0.02 sec)\r\n \r\n<\/pre>\n
\u5173\u95edMySQL\u67e5\u8be2\u65e5\u5fd7<\/strong><\/span><\/div>\n
\r\nmysql> show variables like 'general_log';\r\n+---------------+-------+\r\n| Variable_name | Value |\r\n+---------------+-------+\r\n| general_log   | ON    |\r\n+---------------+-------+\r\n1 row in set (0.01 sec)\r\n \r\nmysql> set global general_log=off;\r\nQuery OK, 0 rows affected (0.01 sec)\r\n \r\nmysql> show variables like 'general_log';\r\n+---------------+-------+\r\n| Variable_name | Value |\r\n+---------------+-------+\r\n| general_log   | OFF   |\r\n+---------------+-------+\r\n1 row in set (0.00 sec)\r\n \r\n<\/pre>\n
\u8bbe\u7f6e\u65e5\u5fd7\u8f93\u51fa\u65b9\u5f0f\u4e3a\u8868<\/strong><\/span><\/div>\n

\u5982\u679c\u8bbe\u7f6elog_output=table\u7684\u8bdd\uff0c\u5219\u65e5\u5fd7\u7ed3\u679c\u4f1a\u8bb0\u5f55\u5230\u540d\u4e3agengera_log\u7684\u8868\u4e2d\uff0c\u8fd9\u8868\u7684\u9ed8\u8ba4\u5f15\u64ce\u662fCSV\uff09\u3002<\/p>\n

\r\nmysql> show variables like 'log_output';\r\n+---------------+-------+\r\n| Variable_name | Value |\r\n+---------------+-------+\r\n| log_output    | FILE  |\r\n+---------------+-------+\r\n1 row in set (0.00 sec)\r\n \r\nmysql> set global log_output='table';\r\nQuery OK, 0 rows affected (0.00 sec)\r\n \r\nmysql> show variables like 'log_output';\r\n+---------------+-------+\r\n| Variable_name | Value |\r\n+---------------+-------+\r\n| log_output    | TABLE |\r\n+---------------+-------+\r\n1 row in set (0.01 sec)\r\n \r\n<\/pre>\n
\u67e5\u770b\u67e5\u8be2\u65e5\u5fd7\u4fe1\u606f\u3002<\/strong><\/span><\/div>\n
\r\nmysql> select * from mysql.general_log;\r\n+---------------------+---------------------------+-----------+-----------+--------------+----------------------------------+\r\n| event_time          | user_host                 | thread_id | server_id | command_type | argument                         |\r\n+---------------------+---------------------------+-----------+-----------+--------------+----------------------------------+\r\n| 2017-07-06 12:32:05 | root[root] @ localhost [] |         1 |         1 | Query        | show variables like 'general%'   |\r\n| 2017-07-06 12:32:28 | root[root] @ localhost [] |         1 |         1 | Query        | show variables like 'log_output' |\r\n| 2017-07-06 12:32:41 | root[root] @ localhost [] |         1 |         1 | Query        | select * from MyDB.test          |\r\n| 2017-07-06 12:34:36 | [root] @ localhost []     |         3 |         1 | Connect      | root@localhost on                |\r\n| 2017-07-06 12:34:36 | root[root] @ localhost [] |         3 |         1 | Query        | KILL QUERY 1                     |\r\n| 2017-07-06 12:34:36 | root[root] @ localhost [] |         3 |         1 | Quit         |                                  |\r\n| 2017-07-06 12:34:51 | root[root] @ localhost [] |         1 |         1 | Query        | select * from mysql.general_log  |\r\n+---------------------+---------------------------+-----------+-----------+--------------+----------------------------------+\r\n7 rows in set (0.02 sec)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u627e\u5230my.ini,\u5728\u4e0b\u9762\u6dfb\u52a0\uff1a log=\u5b58\u653e\u65e5\u5fd7\u7684\u8def\u5f84\/my.log \u4fdd\u5b58\u6587\u4ef6\uff0c\u91cd\u542fmysql\u670d\u52a1\uff0c\u4e4b\u540e\u5c31\u53ef\u4ee5 […]<\/p>\n","protected":false},"author":1903,"featured_media":110423,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-204242","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/204242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1903"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=204242"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/204242\/revisions"}],"predecessor-version":[{"id":204244,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/204242\/revisions\/204244"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/110423"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=204242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=204242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=204242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}