Tony
Tony

Reputation: 9581

Terminal mysql queries

I'm looking to use terminal to execute mysql queries. I currently connect to a sql db via the sql workbench but would like to do this via terminal. Is this possible?

I've installed mysql via homebrew

when I hit mysql in terminal it says command not found, maybe I need to do something else besides the homebrew setup?

Upvotes: 5

Views: 25087

Answers (2)

Atri
Atri

Reputation: 5831

Go to the directory:

mysql/bin

To execute the query from command line:

mysql -u [username] -p [dbname] -e [query]

example:

mysql -u root -p database -e "select * from user"

Upvotes: 10

pamil
pamil

Reputation: 980

mysql --help

You can do also:

cat dump.sql | mysql -u user -p password database

Or:

echo "select * from abc;" | mysql -u user -p password database

Upvotes: 1

Related Questions