Parameter general_log dalam MySQL digunakan untuk mengawal pembukaan dan penutupan log pertanyaan MySQL , dan parameter general_log_file digunakan untuk mengawal Pertanyaan lokasi log. Jika anda ingin menentukan sama ada pangkalan data MySQL telah mengaktifkan pengelogan pertanyaan, anda boleh menggunakan arahan berikut. Jika general_log ditetapkan kepada HIDUP, log pertanyaan akan dihidupkan; jika ia ditetapkan kepada MATI, log pertanyaan akan dimatikan.
mysql> show variables like '%general_log%'; +------------------+------------------------------+ | Variable_name | Value | +------------------+------------------------------+ | general_log | OFF | | general_log_file | /var/lib/mysql/DB-Server.log | +------------------+------------------------------+ 2 rows in set (0.00 sec)
Selain itu, log pertanyaan MySQL menyokong menulis ke fail atau menulis ke jadual data Ini dikawal oleh parameter log_output, seperti yang ditunjukkan di bawah:
mysql> show variables like 'log_output'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | FILE | +---------------+-------+ 1 row in set (0.00 sec)
mysql> set global general_log = on; Query OK, 0 rows affected (0.11 sec) mysql> show variables like 'general_log'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | general_log | ON | +---------------+-------+ 1 row in set (0.02 sec)
mysql> show variables like 'general_log'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | general_log | ON | +---------------+-------+ 1 row in set (0.01 sec) mysql> set global general_log=off; Query OK, 0 rows affected (0.01 sec) mysql> show variables like 'general_log'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | general_log | OFF | +---------------+-------+ 1 row in set (0.00 sec)
Jika log_output=jadual ditetapkan, keputusan log akan direkodkan ke jadual bernama genera_log Jadual ini enjin ialah CSV).
mysql> show variables like 'log_output'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | FILE | +---------------+-------+ 1 row in set (0.00 sec) mysql> set global log_output='table'; Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'log_output'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | TABLE | +---------------+-------+ 1 row in set (0.01 sec)
mysql> select * from mysql.general_log; +---------------------+---------------------------+-----------+-----------+--------------+----------------------------------+ | event_time | user_host | thread_id | server_id | command_type | argument | +---------------------+---------------------------+-----------+-----------+--------------+----------------------------------+ | 2017-07-06 12:32:05 | root[root] @ localhost [] | 1 | 1 | Query | show variables like 'general%' | | 2017-07-06 12:32:28 | root[root] @ localhost [] | 1 | 1 | Query | show variables like 'log_output' | | 2017-07-06 12:32:41 | root[root] @ localhost [] | 1 | 1 | Query | select * from MyDB.test | | 2017-07-06 12:34:36 | [root] @ localhost [] | 3 | 1 | Connect | root@localhost on | | 2017-07-06 12:34:36 | root[root] @ localhost [] | 3 | 1 | Query | KILL QUERY 1 | | 2017-07-06 12:34:36 | root[root] @ localhost [] | 3 | 1 | Quit | | | 2017-07-06 12:34:51 | root[root] @ localhost [] | 1 | 1 | Query | select * from mysql.general_log | +---------------------+---------------------------+-----------+-----------+--------------+----------------------------------+ 7 rows in set (0.02 sec)
Atas ialah kandungan terperinci Bagaimana untuk melihat rekod operasi pangkalan data mysql di bawah Linux. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!