一、
1.创建数据库,
mysql> CREATE DATABASE IF NOT EXISTS SECOND_DB;
Query OK, 1 row affected (0.01 sec)
2.删除数据库,
mysql> DROP DATABASE IF EXISTS SECOND_DB;
Query OK, 0 rows affected (0.11 sec)
3.查询创建数据的语句,
mysql> CREATE DATABASE SECOND_DB DEFAULT CHARACTER SET UTF8MB4 COLLATE utf8mb4_bin;
Query OK, 1 row affected (0.00 sec)
mysql> SHOW CREATE DATABASE SECOND_DB;
+-----------+------------------------------------------------------------------------------------------------------------------------------+
| Database | Create Database |
+-----------+------------------------------------------------------------------------------------------------------------------------------+
| SECOND_DB | CREATE DATABASE `SECOND_DB` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin */ /*!80016 DEFAULT ENCRYPTION='N' */ |
+-----------+------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
4.使用数据库,查询当前默认的数据库以及使用的编码方式校验规则
mysql> USE SECOND_DB;
Database changed
mysql> SELECT @@character_set_database, @@collation_database;
+--------------------------+----------------------+
| @@character_set_database | @@collation_database |
+--------------------------+----------------------+
| utf8mb4 | utf8mb4_bin |
+--------------------------+----------------------+
1 row in set (0.00 sec)
二、数字,文本,日期
在一章表中定义多个字段,要使用今天提到的所有的数据类型
1.txt类型
2.number类型
注意:这些整数类型拥有额外的选项 UNSIGNED。通常,整数可以是负数或正数。如果添加 UNSIGNED属性,那么范围将从 0 开始,而不是某个负数。
3.Date类型
创建图书表:
mysql> create table book_tb(
-> bookid int(11) comment '图书编号',
-> book_name char(6) comment '图书名称',
-> publishinghouse varchar(50) comment '出版社',
-> bookreview tinytext comment '书评',
-> bookintroduction text comment '图书简介',
-> main mediumtext comment '主要内容',
-> speak longtext comment '作者推荐',
-> readingcheck blob comment '读者推荐',
-> phintroduction mediumblob comment '出版社推荐',
-> expertintroduction longblob comment '专家点评推荐',
-> paginalnumber tinyint comment '图书页数',
-> btnumber smallint comment '图书类数',
-> booknumber mediumint comment '图书数量',
-> character_num bigint comment '全书字数',
-> publishingdate date comment '出版日期',
-> plansaledate datetime comment '预售日期' ,
-> madeday timestamp comment '创作日期',
-> borrowtime time comment '借阅时间',
-> Booktime year comment '图书年份'
-> )engine=InnoDB default character set utf8mb4 collate utf8mb4_bin;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql>