MySQL Quick Reference

To open MySQL:

mysql -u (username) -p

To create a database:

create database (name)

To select a database:

use (database)

To create a table within the database:

create table (name) (
ID int not null auto_increment primary key,
(col1 name) (col1type),

To display the details of a table:

describe (table)

Correcting a table’s properties:

alter table (tablename) modify (columnname) (columntype)

Adding records to a table:

insert into (tablename) set 

Changing records in a table:

update (tablename) set 

Deleting records:

delete from (tablename) where (columnname) like (value);

To query only unique values (i.e. no duplicates):

SELECT DISTINCT colname FROM tablename;

To copy contents of one table to another:

INSERT INTO newtable(col1, col2)
SELECT oldcol1, oldcol2
FROM oldtable

Deleting a table:

DROP TABLE (tablename);

Convert table to InnoDB:

alter table Tablename engine=”InnoDB”;

Leave a Reply