gpt4 book ai didi

mysql命令行选项

转载 作者:太空宇宙 更新时间:2023-11-04 09:53:16 24 4
gpt4 key购买 nike

mysql 中的命令行选项 -e 或 --execute 用于在 shell 提示符本身中执行命令。如果查询不成功(如果输出为零的数字?),有没有办法打印错误?就像

Empty set (0.89 sec)

最佳答案

mysql 默认情况下已经打印出错误消息。如果发生错误,它也会以大于 0 的退出代码退出:

$ mysql -e "SHOW VARIABLES LIKE 'version' THIS WON'T WORK"
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'THIS WON'T WORK' at line 1
$ echo $?
1
$ mysql -e "SHOW VARIABLES LIKE 'version'"
+---------------+------------+
| Variable_name | Value |
+---------------+------------+
| version | 5.5.19-log |
+---------------+------------+
$ echo $?
0

关于mysql命令行选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8634544/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com