一.建立数据库
mysql> create database db_classes
-> default charset = utf8mb4;
Query OK, 1 row affected (0.03 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| db_classes |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
二.建立表
mysql> use db_classes;
Database changed
mysql> show tables;
Empty set (0.01 sec)
mysql> create table db_hero(
-> id int not null,
-> name varchar(100) not null,
-> world varchar(100),
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> desc db_hero;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id | int | NO | | NULL | |
| name | varchar(100) | NO | | NULL | |
| world | varchar(100) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
9 rows in set (0.00 sec)
三.插入数据
mysql> insert into db_hero values(1,"孙悟空","西游记");
Query OK, 1 row affected (0.01 sec)
mysql> insert into db_hero values(2,"林黛玉","红楼梦");
Query OK, 1 row affected (0.01 sec)
mysql> insert into db_hero values(3,"李逵","水浒传");
Query OK, 1 row affected (0.00 sec)
mysql> insert into db_hero values(4,"赵云","三国演义");
Query OK, 1 row affected (0.00 sec)
mysql> insert into db_hero values(5,"白龙马","西游记");
Query OK, 1 row affected (0.00 sec)
mysql> insert into db_hero values(6,"紫霞仙子","西游计");
Query OK, 1 row affected (0.00 sec)
结果
mysql> show tables;
+----------------------+
| Tables_in_db_classes |
+----------------------+
| db_hero |
+----------------------+
1 row in set (0.00 sec)
mysql> select * from db_hero;
+----+--------------+-----------------+------+--------+--------------+-----------------+--------------+--------+
| id | name | world |
+----+--------------+-----------------+------+--------+--------------+-----------------+--------------+--------+
| 1 | 孙悟空 | 西游记 |
| 2 | 林黛玉 | 红楼梦 |
| 3 | 李逵 | 水浒传 |
| 4 | 赵云 | 三国演义 |
| 5 | 白龙马 | 西游记 |
| 6 | 紫霞仙子 | 西游计 |
+----+--------------+-----------------+------+--------+--------------+-----------------+--------------+--------+
6 rows in set (0.00 sec)