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?
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"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With