How to execute MySQL query / statement from the shell (command line)

mysql -hhostname -uusername -ppassword db_name -e 'query to execute;'
  • hostname – the host on which MySQL is installed
  • username – the MySQL user that has the necessary privileges over the database
  • passsword – the MySQL user password
  • db_name – the name of the MySQL database that you want to query
  • -e – MySQL option which will execute the statement and quit
  • query to execute; – the MySQL query you want to execute enclosed in single quotes
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s