Introduction to basic MySQL commands Print

  • 29

Although most commands sent to the MySQL server aren't case sensitive, it's a good habit to use proper case with all commands. For instance, commands are in upper-case, and table/database names are in lower-case. Although difficult at first, it makes reading your own query statments much easier. 

Note: All these commands are intended to be run from your account's shell. 

Connecting to the mysql server: 
mysql -h "mysql server" -u "username" -p 

You'll be prompted for the password. 

The following commands are ran after you have connected to the MySQL server. 

To select a database: 
USE "database"; 

Display a list of your databases tables: 
SHOW TABLES; 

Display the columns in a table: 
SHOW COLUMNS FROM "table"; 

Display the contents of all the columns in a table: 
SELECT * FROM "table"; 

Display a specific column(s) in a table: 
SELECT "column name" FROM "table"; 

or 

SELECT "column 1","column 2" FROM "table"; 

You can select any number/combination of columns. 

Disconnect from the MySQL server: 
QUIT; 

Was this answer helpful?

« Back