如何显示刚刚发生的 MySQL 警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1215692/
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
How do I show a MySQL warning that just happened?
提问by Pops
I just ran a simple MySQL CREATE TABLE statement that produced the line
我刚刚运行了一个简单的 MySQL CREATE TABLE 语句,该语句生成了该行
"Query OK, 0 rows affected, 1 warning (0.07 sec)."
“查询正常,0 行受影响,1 个警告(0.07 秒)。”
It didn't actually show me what the warning was, though. How can you see the contents of a warning that just occurred? I'm using MySQL 5.1, if it makes a difference. The only thing I found online was "SHOW WARNINGS;" but that only produced
不过,它实际上并没有向我展示警告是什么。如何查看刚刚发生的警告的内容?我正在使用 MySQL 5.1,如果它有所不同的话。我在网上找到的唯一内容是“显示警告”;但这只产生了
"Empty set (0.00 sec)."
“空集(0.00 秒)。”
回答by zombat
SHOW WARNINGS
is the only method I'm aware of, but you have to run it immediately after a query that had warnings attached to it. If you ran any other queries in between, or dropped the connection, then SHOW WARNINGS
won't work.
SHOW WARNINGS
是我知道的唯一方法,但是您必须在附加了警告的查询之后立即运行它。如果您在两者之间运行任何其他查询,或断开连接,SHOW WARNINGS
则将无法工作。
The MySQL manual page for SHOW WARNINGSdoesn't indicate any other methods, so I'm fairly certain that you're stuck with it.
SHOW WARNINGS的 MySQL 手册页没有指出任何其他方法,所以我很确定你坚持使用它。
回答by HorusKol
You can also set the command line to always display warnings after a query using \W
您还可以使用 \W 将命令行设置为在查询后始终显示警告
You can switch them off again with \w
你可以用 \w 再次关闭它们
回答by Pops
@HorusKol, do you have documentation for that? I couldn't find any. But I did find out that the command line option --show-warnings
will do the job, according to the MySQL manual.
@HorusKol,您有相关文档吗?我找不到任何。但我确实发现命令行选项--show-warnings
可以完成这项工作,根据MySQL 手册。