Mysql – thesql not to print selects output to terminal

MySQLshellterminal

Quick question:
I have created come commands that will warm-up my DB.
The thing is that those selects are large.
When I do such a select I get all the "jiba-jaba" into my terminal window.
How can you make mysql do the select 'quietly' ? without taking ages to print all the crap into my terminal ?

Best Answer

You can redirect the output of any command -- not just MySQL -- by using your shell's i/o redirection operators. For example, in bash:

$ mysql mydb < commands.sql > /dev/null 2>&1

This will launch the MySQL command line client, connect it to "mydb" on the local system (assuming you have access), read SQL commands from the file commands.sql and dump all the output to /dev/null.

If you wanted to save the output for review after the fact, you could redirect it to a file rather than to /dev/null:

$ mysql mydb < commands.sql > output.txt 2>&1

The 2>&1 redirects stderr as well as stdout. If you wanted to see any errors on your terminal, you would only redirect stdout:

$ mysql mydb < commands.sql > /dev/null
Related Topic