Wednesday, April 06, 2011

MySQL - Run SQL Queries From A cmd prompt

Data setup and tear down is a common task during development and testing. Ability to execute sql queries from command prompt allows developers to automate these tasks.

You can achieve this by using the following command -

mysql -u user -p -e 'SQL Query' database

Where,
-u : Specify mysql database user name
-p : Prompt for password
-e : Execute sql query
database : Specify database name

note : You don't need to specify user and password if you have not set up authentication.

No comments: