Creating First Table in MySQL

A tutorial example is provided on how to verify a new installation of MySQL 5.7.10 by creating a new test table and insert some data to the table.

In the previous section, we learned how to start and shutdown MySQL server. Now let's see how we can use MySQL client interface to create a table and run queries.

Make sure MySQL server is running. Start the MySQL client interface in a command window, and run the following MySQL client commands:

C:\herong>"\Program Files\MySQL\MySQL Server 5.7\bin\mysql" 
   --user=root --password=TopSecret
mysql: [Warning] Using a password on the command line interface can be
insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.10-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights 
reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input 
statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
6 rows in set (0.07 sec)

mysql> create database test;
Query OK, 1 row affected (0.01 sec)

mysql> use test;
Database changed

mysql> create table hello (message varchar(80));
Query OK, 0 rows affected (1.24 sec)

mysql> insert into hello (message) value ('Hello world!');
Query OK, 1 row affected (0.31 sec)

mysql> select * from hello;
+--------------+
| message      |
+--------------+
| Hello world! |
+--------------+
1 row in set (0.00 sec)

mysql> drop table hello;
Query OK, 0 rows affected (0.97 sec)

mysql> quit;
Bye

Last update: 2015.

Table of Contents

 About This Book

 Introduction of SQL

MySQL Introduction and Installation

 What Is MySQL?

 Downloading and Installing MySQL

 Issues during MySQL Installation

 Starting and Stopping MySQL Server

Creating First Table in MySQL

 Un-Installing MySQL

 Using MySQL Noinstall Package

 Introduction of MySQL Programs

 Perl Programs and MySQL Servers

 PHP Programs and MySQL Servers

 Java Programs and MySQL Servers

 Datatypes and Data Literals

 Operations and Expressions

 Character Strings and Bit Strings

 Commonly Used Functions

 Table Column Types for Different Types of Values

 Using DDL to Create Tables and Indexes

 Using DML to Insert, Update and Delete Records

 Using SELECT to Query Database

 Transaction Management and Isolation Levels

 Locks Used in MySQL

 Defining and Calling Stored Procedures

 Variables, Loops and Cursors Used in Stored Procedures

 Outdated Tutorials

 References

 PDF Printing Version