Today I was playing with MySQL command line under Windows (I use XAMPP for this). Thanks to the MySQL cookbook I learned about the -e option. This is great, because with this -e option you can pipe MySQL to stdin, so I have learned.
For example:
c:\xampp\mysql\bin>mysql -u root -p your_password -e "select * from dbase_name.table_name" | logparser "select * from stdin" -i:tsv -o:datagrid
By default, results generated by queries that are specified with -e are displayed in tabular format if output goes to the terminal, and in tab-delimited format otherwise. This can come in handy especially when you combine MySQL with MS logparser !
Of course, you can use the -e option also for more common tasks, such as storing the output of the query in a file which you can open with Microsoft Excel, for example:
c:\xampp\mysql\bin>mysql -u root -p your_password -e "select * from dbase_name.table_name" > c:\my_files\my_output.csv
One more cool thing about the -e option is that you can use multiple queries in one line, as long as you delimited them with ;
for example:
C:\xampp\mysql\bin>mysql -u root -p -e "use dbase_name; show tables; desc table_name; select * from table_name where col_name = 'test'"
By the way, if you let the -e precede by a -H, a nice HTML page with the results of your query will be created ! Do you prefer to create an XML page, no problemo, just let the -e precede by a -X
Comments