1

I want to know what option makes the commandline execution of MySQL, on an empty reply, print empty set.

mysql -u root -p myPassword mytable -e "select * from names where first="%andrew%"\G"

If this query returns empty set, then the commandline execution exits without printing that there was no answer. How to make it print empty set?

The verbose mode only prints the query.

2 Answers 2

1

You can try -q (quick) option.

Let's see -- 1 row result:

$ mysql database -q -e 'select username,user_id from ... where true limit 1'
+---------------------------+----------+
| username                  | user_id  |
+---------------------------+----------+ 
| administrator             |     1111 | 
+---------------------------+----------+

and now empty set:

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

I think it's some sort of implementation detail in mysql command due to unbuffered output. Don't be surprised if they change it in future versions.

Sign up to request clarification or add additional context in comments.

Comments

0

you can check it in 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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.