Page 1 of 1

Solved: How to execute a SQL query from shell

Posted: Mon Dec 27, 2010 8:04 pm
by mister_v
Hello,

How do I execute a SQL query directly from shell command line?

Thanks,

Re: How to execute a SQL query from shell

Posted: Tue Apr 19, 2011 7:31 pm
by chris
The easiest way I know is with the SQL-command.

Code: Select all

mysql -u user -p -e 'SELECT data FROM table;' database
If you want juts the data:

Code: Select all

mysql -u user -p'password' -sNe 'SELECT data FROM table;' database
-s : separates the values with only tabs
N : skips the column names

-p the password (without spaces, not even between the -p and the password )
else use --password='password.'