MySQL 如何从 SHOW PROCESSLIST 查看完整查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3638689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:03:49  来源:igfitidea点击:

How to see full query from SHOW PROCESSLIST

mysql

提问by Ghostrider

When I issue SHOW PROCESSLIST query, only first 100 characters of the running SQL query are returned in the info column.

当我发出 SHOW PROCESSLIST 查询时,信息列中只返回正在运行的 SQL 查询的前 100 个字符。

Is it possible to change Mysql config or issue a different kind of request to see complete query (the queries I'm looking at are longer than 100 characters)

是否可以更改 Mysql 配置或发出不同类型的请求以查看完整查询(我正在查看的查询超过 100 个字符)

回答by James McNellis

SHOW FULL PROCESSLIST

If you don't use FULL, "only the first 100 characters of each statement are shown in the Infofield".

如果不使用FULL,则Info字段中仅显示每个语句的前 100 个字符”

When using phpMyAdmin, you should also click on the "Full texts" option ("← T →" on top left corner of a results table) to see untruncated results.

使用 phpMyAdmin 时,您还应该单击“全文”选项(结果表左上角的“← T →”)以查看未截断的结果。

回答by Yogesh A Sakurikar

Show Processlist fetches the information from another table. Here is how you can pull the data and look at 'INFO' column which contains the whole query :

Show Processlist 从另一个表中获取信息。以下是提取数据并查看包含整个查询的“INFO”列的方法:

select * from INFORMATION_SCHEMA.PROCESSLIST where db = 'somedb';

You can add any condition or ignore based on your requirement.

您可以根据您的要求添加任何条件或忽略。

The output of the query is resulted as :

查询的输出结果如下:

+-------+------+-----------------+--------+---------+------+-----------+----------------------------------------------------------+
| ID    | USER | HOST            | DB     | COMMAND | TIME | STATE     | INFO                                                     |
+-------+------+-----------------+--------+---------+------+-----------+----------------------------------------------------------+
|     5 | ssss | localhost:41060 | somedb | Sleep   |    3 |           | NULL                                                     |
| 58169 | root | localhost       | somedb | Query   |    0 | executing | select * from sometable where tblColumnName = 'someName' |

回答by hardcoder

I just read in the MySQL documentationthat SHOW FULL PROCESSLISTby default only lists the threads from your current user connection.

我刚刚在MySQL 文档中读到,SHOW FULL PROCESSLIST默认情况下只列出来自当前用户连接的线程。

Quote from the MySQL SHOW FULL PROCESSLIST documentation:

引自 MySQL SHOW FULL PROCESSLIST 文档:

If you have the PROCESS privilege, you can see all threads.

如果您有 PROCESS 权限,则可以看到所有线程。

So you can enable the Process_privcolumn in your mysql.usertable. Remember to execute FLUSH PRIVILEGESafterwards :)

因此,您可以启用表中的Process_privmysql.user。记得FLUSH PRIVILEGES之后执行:)

回答by Hasib Kamal

See full query from SHOW PROCESSLIST :

查看来自 SHOW PROCESSLIST 的完整查询:

SHOW FULL PROCESSLIST;

Or

或者

 SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST;

回答by cristianoms

If one want to keep getting updated processes (on the example, 2 seconds) on a shell session without having to manually interact with it use:

如果您想在 shell 会话中保持更新进程(在示例中为 2 秒)而无需手动与其交互,请使用:

watch -n 2 'mysql -h 127.0.0.1 -P 3306 -u some_user -psome_pass some_database -e "show full processlist;"'

The only bad thing about the show [full] processlistis that you can't filter the output result. On the other hand, issuing the SELECT * FROM INFORMATION_SCHEMA.PROCESSLISTopen possibilities to remove from the output anything you don't want to see:

唯一不好的show [full] processlist是你不能过滤输出结果。另一方面,发出SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST开放的可能性以从输出中删除您不想看到的任何内容:

SELECT * from INFORMATION_SCHEMA.PROCESSLIST
WHERE DB = 'somedatabase'
AND COMMAND <> 'Sleep'
AND HOST NOT LIKE '10.164.25.133%' \G