MySQL - How to create a table in MySQL?

1. Using query editor

To create a table in MySQL:

CREATE TABLE table_name (
col1 data_type1,
col2 data_type2,
col3 data_type3,
col4 data_type4,
…
);

For example, you want to create a table customers with 4 columns: id, name, email, city:

CREATE TABLE customers (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
email VARCHAR(50),
city VARCHAR(50)
);

After the data type, you can specify some additional attributes:

  • PRIMARY KEY - unique identifier of the row
  • DEFAULT - add default value
  • NOT NULL - null values are not allowed. Row has to contain value.
  • UNSIGNED - limits the stored data to positive numbers and zero
  • AUTO_INCREMENT - automatically increases the value of the field by 1 each time a new row is added

2. Using TablePlus GUI

In TablePlus, you can create a table from its GUI tool:

  • While connected to the database, click on the + button at the bottom of the left sidebar
  • Click on the + Column button, or double click on the empty row to add a new column
  • Specify the new column description
  • When it's done, press Cmd + S to commit changes to the server.
Create a new table MySQL

*Need a good GUI Tool for MySQL? TablePlus is a modern, native tool with an elegant UI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.
*

Download TablePlus for Mac.

Not on Mac? Download TablePlus for Windows.

On Linux? Download TablePlus for Linux

Need a quick edit on the go? Download TablePlus for iOS.

TablePlus GUI Tool MySQL

← All posts