Search  
Resources & Services: Computing

Basic MySQL

 

Here are some basic commands to use MySQL from the command line.


Logging in to MySQL from the command line

After logging into the server type: mysql -u username -p

You will then be prompted for your password.

View/Change Databases

Now that you have logged in the the MySQL server you will need to access a database. To view a list of all the available databases type: show databases

To change your current database you will need to type: use yourdatabase

View Tables in a Database

Type: show tables

View Columns with in a table

Type: show columns from tablename;

Show all records from a table

Type: select * from tablename;

Show records from selected columns in a table

Type: select colname1, colname2, colname3 from tablename;

Filtering results in a query

Single Filter
Type: select * from tablename where columnname1 = 'critiera';

Two Filters (using both)
Type: select * from tablename where columnname1 = 'critiera' and columnname2 = 'critiera 2';

Two Filters (using either)
Type: select * from tablename where columnname1 = 'critiera' or columnname2 = 'critiera 2';

Sorting results in a query

Type: select * from tablename order by columnname1, columnname2;

Search