FiveFeet

MySQL Run SQL Queries From A Shell Prompt/Command Line

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

To list all database, enter:
$ mysql -u username -p -e 'show databases;'

To list count all rows, enter:
$ mysql -u username -p -e 'SELECT COUNT(*) FROM quotes' databaseName

Redirect out to a file:
$ mysql -u username -p 'PassWord' -e 'SELECT COUNT(*) FROM quotes' databaseName > sql.output.txt

To import SQL file:
mysql -u username -p database_name < textfilewithsqlstatments.sql