Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL命令行执行_Mysql_Bash_Command Line - Fatal编程技术网

MySQL命令行执行

MySQL命令行执行,mysql,bash,command-line,Mysql,Bash,Command Line,我想知道是什么选项使得MySQL的命令行执行在一个空的回复上打印空集 mysql-u root-p myPassword mytable-e从名称中选择* 第一个=%andrew%\G 如果此查询返回空集,则命令行执行将退出,而不打印没有答案。如何使其打印空集 详细模式只打印查询。您可以在bash中检查它 if [ "a$(mysql -u root -p myPassword mytable -e "select * from names where first="%andrew%"\G")"

我想知道是什么选项使得MySQL的命令行执行在一个空的回复上打印空集

mysql-u root-p myPassword mytable-e从名称中选择* 第一个=%andrew%\G

如果此查询返回空集,则命令行执行将退出,而不打印没有答案。如何使其打印空集


详细模式只打印查询。

您可以在bash中检查它

if [ "a$(mysql -u root -p myPassword mytable -e "select * from names where first="%andrew%"\G")" = "a" ]
then 
    echo Empty set
else
    echo Not empty set
fi

您可以在bash中检查它

if [ "a$(mysql -u root -p myPassword mytable -e "select * from names where first="%andrew%"\G")" = "a" ]
then 
    echo Empty set
else
    echo Not empty set
fi

您可以尝试-q快速选项

让我们看看-1行结果:

$ mysql database -q -e 'select username,user_id from ... where true limit 1'
+---------------------------+----------+
| username                  | user_id  |
+---------------------------+----------+ 
| administrator             |     1111 | 
+---------------------------+----------+
现在是空集:

$ mysql database -q -e 'select username,user_id from ... where false'
+---------------------------+----------+
| username                  | user_id  |
+---------------------------+----------+
+---------------------------+----------+

我认为这是mysql命令中的某种实现细节,因为没有缓冲输出。如果他们在将来的版本中更改了它,不要感到惊讶。

您可以尝试-q快速选项

让我们看看-1行结果:

$ mysql database -q -e 'select username,user_id from ... where true limit 1'
+---------------------------+----------+
| username                  | user_id  |
+---------------------------+----------+ 
| administrator             |     1111 | 
+---------------------------+----------+
现在是空集:

$ mysql database -q -e 'select username,user_id from ... where false'
+---------------------------+----------+
| username                  | user_id  |
+---------------------------+----------+
+---------------------------+----------+
我认为这是mysql命令中的某种实现细节,因为没有缓冲输出。如果他们在将来的版本中更改了它,不要感到惊讶