Mysql – How to “select * from table from database” with -e

MySQL

I want to select and show 1 row form a table with the mysql -e.

I was trying out the following but no luck,

mysql -u root -e “select * from table1 from db01 limit 1”

Actually I am trying to dump a single line from hundreads of tables to take a sample from them and redirect to a file. So I want to use shell and don’t want to be in MySQL console.

I have used show the above way but select is not working.

Everyone is suggesting to do select * from table1 but didn’t mentioned how to mention database.
So how can I achieve this?

Best Answer

You have to from in your Select use only one Like in my post

use out file like

mysql -u root -e “select * from db01.table1 limit 1” > /tmp/output

Which looks like

+----------+
| count(*) |
+----------+
|      471 | 
+----------+