How to show the last queries executed on MySQL?

2018-12-31 10:07发布

Is there any query/way to show the last queries executed on ALL servers?

标签: mysql logging
10条回答
大哥的爱人
2楼-- · 2018-12-31 10:35

You can look at the following in linux

cd /root

ls -al

vi .mysql_history It may help

查看更多
荒废的爱情
3楼-- · 2018-12-31 10:37
SELECT * FROM  mysql.general_log  WHERE command_type ='Query' LIMIT total;
查看更多
闭嘴吧你
4楼-- · 2018-12-31 10:38

1) If general mysql logging is enabled then we can check the queries in the log file or table based what we have mentioned in the config. Check what is enabled with the following command

mysql> show variables like 'general_log%';
mysql> show variables like 'log_output%';

If we need query history in table then

Execute SET GLOBAL log_output = 'TABLE';
Execute SET GLOBAL general_log = 'ON';

Take a look at the table mysql.general_log

If you prefer to output to a file:

SET GLOBAL log_output = "FILE"; which is set by default.
SET GLOBAL general_log_file = "/path/to/your/logfile.log";
SET GLOBAL general_log = 'ON';

2) We can also check the queries in the .mysql_history file cat ~/.mysql_history

查看更多
何处买醉
5楼-- · 2018-12-31 10:40

You can enable a general query log for that sort of diagnostic. Generally you don't log all SELECT queries on a production server though, it's a performance killer.

Edit your MySQL config, e.g. /etc/mysql/my.cnf - look for, or add, a line like this

[mysqld]
log = /var/log/mysql/mysql.log

Restart mysql to pick up that change, now you can

tail -f /var/log/mysql/mysql.log

Hey presto, you can watch the queries as they come in.

查看更多
登录 后发表回答