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)
相关推荐
云和数据.ChenGuang3 分钟前
Django 应用安装脚本 – 如何将应用添加到 INSTALLED_APPS 设置中 原创
数据库·django·sqlite
woshilys31 分钟前
sql server 查询对象的修改时间
运维·数据库·sqlserver
Hacker_LaoYi31 分钟前
SQL注入的那些面试题总结
数据库·sql
建投数据1 小时前
建投数据与腾讯云数据库TDSQL完成产品兼容性互认证
数据库·腾讯云
Hacker_LaoYi2 小时前
【渗透技术总结】SQL手工注入总结
数据库·sql
岁月变迁呀3 小时前
Redis梳理
数据库·redis·缓存
独行soc3 小时前
#渗透测试#漏洞挖掘#红蓝攻防#护网#sql注入介绍06-基于子查询的SQL注入(Subquery-Based SQL Injection)
数据库·sql·安全·web安全·漏洞挖掘·hw
你的微笑,乱了夏天3 小时前
linux centos 7 安装 mongodb7
数据库·mongodb
工业甲酰苯胺3 小时前
分布式系统架构:服务容错
数据库·架构
独行soc4 小时前
#渗透测试#漏洞挖掘#红蓝攻防#护网#sql注入介绍08-基于时间延迟的SQL注入(Time-Based SQL Injection)
数据库·sql·安全·渗透测试·漏洞挖掘