How to Create a Table in MySQL Database

From Brian Nelson Ramblings
Revision as of 20:30, 12 March 2014 by Brian (Talk | contribs) (Created page with "==How to create a table in a MySQL database== Now that you have created your database, you will need to add some tables. Lets first log into mysql via the command line mys...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to create a table in a MySQL database

Now that you have created your database, you will need to add some tables.

Lets first log into mysql via the command line

mysql -u <username> -p 
use <databasename>

Now lets create the table, this is a simple table we use to track traffic on a site.

CREATE TABLE visitors (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, 
browser VARCHAR(50),
page VARCHAR(30),
confirmed CHAR(1), 
signup_date DATE);

NOTE: MySQL does not terminate a command until you give a semicolon (;) at the end of SQL command.

Now lets check and confirm the table was inserted.

SHOW TABLES;

If you want to see the structure of the table

DESCRIBE visitors;