MySQL---创建数据库与表

一.建立数据库

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)
相关推荐
CoderIsArt37 分钟前
Redis的三种模式:主从模式,哨兵与集群模式
数据库·redis·缓存
师太,答应老衲吧3 小时前
SQL实战训练之,力扣:2020. 无流量的帐户数(递归)
数据库·sql·leetcode
Yaml44 小时前
Spring Boot 与 Vue 共筑二手书籍交易卓越平台
java·spring boot·后端·mysql·spring·vue·二手书籍
Channing Lewis4 小时前
salesforce case可以新建一个roll up 字段,统计出这个case下的email数量吗
数据库·salesforce
追风林4 小时前
mac 本地docker-mysql主从复制部署
mysql·macos·docker
毕业设计制作和分享5 小时前
ssm《数据库系统原理》课程平台的设计与实现+vue
前端·数据库·vue.js·oracle·mybatis
ketil275 小时前
Redis - String 字符串
数据库·redis·缓存
Hsu_kk6 小时前
MySQL 批量删除海量数据的几种方法
数据库·mysql
编程学无止境6 小时前
第02章 MySQL环境搭建
数据库·mysql
knight-n6 小时前
MYSQL库的操作
数据库·mysql