mysql中的命令行选项-e或--execute用于在shell提示符本身中执行命令。如果查询不成功,有没有办法打印错误(如果输出的数字是零?) 就像
Empty set (0.89 sec)
答案 0 :(得分:2)
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