MySQL - Command line cheatsheet

By xngo on November 15, 2019

Execute query

# Execute queries from string.
$mysql -hLOCALHOST -uROOT -pPASSWORD DBNAME -e "SELECT 1 as Header; SELECT 1"
+--------+
| Header |
+--------+
|      1 |
+--------+
+---+
| 1 |
+---+
| 1 |
+---+
 
# Execute queries from file.
$mysql -hLOCALHOST -uROOT -pPASSWORD < queries.sql

Get results with no formatting

mysql --skip-column-names --silent -hLOCALHOST -uROOT -ppassword DBNAME -e "SELECT 1 as Header"
  • --skip-column-names: Will not display the column header name.
  • --silent: Will not display the cell's border.

Output

1

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.