# mysql: execute queries from bash

## pactoo

Hello,

I am trying to do a simple query of a mysql database from bash. But I do not want to read that query from a script. 

Something like: 

mysql -u USER -pPASS -D database "select * from table;"

Instead of: 

mysql -u USER -pPASS -D database < file.sql

Currently I am having trouble realising this

----------

## tomk

This is the way I do queries from bash:

```
echo "select * from table;" | mysql -u USER -pPASS -D database
```

If you don't want the column names displayed as the first row add -s to the mysql options. You can also change the output format: -H for HTML, -t for table, -E for vertical or -X for XML.

----------

## BrummBrumm

hi.

try this:

mysql --user="someuser" --password="pw" -D "dbname" -e 'your-sql-command;'

you can also do something like

mysql --user="user" --password="pw" << EOF

command-1;

command-2;

EOF

----------

## pactoo

Thanks very much. For some reason, I have overseen (or misinterpreted) the "-e" option. Multiple times actually. However, the other hints may be helpful, too

----------

