• 安装好mysql表项目
  • 连接sql

2022-05-26T03:25:30.png

3.数据初始化

  • 列表创建数据表
CREATE DATABASE
IF
    NOT EXISTS books DEFAULT charset utf8;
USE books;
DROP TABLE
IF
    EXISTS `t_book`;
CREATE TABLE `t_book` (
    `id` INT ( 11 ) NOT NULL auto_increment,
    `title` VARCHAR ( 20 ) NOT NULL COMMENT '图书名称',
    `pub_date` date NOT NULL COMMENT '发布日期',
    `read` INT ( 11 ) NOT NULL DEFAULT '0' COMMENT '阅读量',
    `comment` INT ( 11 ) NOT NULL DEFAULT '0' COMMENT '评论量',
    `is_delete` TINYINT ( 1 ) NOT NULL DEFAULT '0' COMMENT '逻辑删除',
    PRIMARY KEY ( `id` ) 
) ENGINE = INNODB DEFAULT CHARSET = utf8 COMMENT = '图书表';
INSERT INTO `t_book`
VALUES
    ( '1', '射雕英雄传', '1980-05-01', '12', '34', '0' );
INSERT INTO `t_book`
VALUES
    ( '2', '天龙八部', '1986-07-24', '36', '40', '0' );
INSERT INTO `t_book`
VALUES
    ( '3', '笑傲江湖', '1995-12-24', '20', '80', '0' );
DROP TABLE
IF
    EXISTS `t_hero`;
CREATE TABLE `t_hero` (
    `id` INT ( 11 ) NOT NULL auto_increment,
    `name` VARCHAR ( 20 ) NOT NULL COMMENT '姓名',
    `gender` SMALLINT ( 6 ) NOT NULL COMMENT '性别',
    `description` VARCHAR ( 200 ) DEFAULT NULL COMMENT '描述',
    `is_delete` TINYINT ( 1 ) NOT NULL DEFAULT '0' COMMENT '逻辑删除',
    `book_id` INT ( 11 ) NOT NULL COMMENT '所属图书ID',
    PRIMARY KEY ( `id` ),
    KEY `t_hero_book_id` ( `book_id` ) 
) ENGINE = INNODB DEFAULT CHARSET = utf8 COMMENT = '英雄人物表';
INSERT INTO `t_hero`
VALUES
    ( '1', '郭靖', '1', '降龙十八掌', '0', '1' );
INSERT INTO `t_hero`
VALUES
    ( '2', '黄蓉', '0', '打狗棍法', '0', '1' );
INSERT INTO `t_hero`
VALUES
    ( '3', '乔峰', '1', '降龙十八掌', '0', '2' );
INSERT INTO `t_hero`
VALUES
    ( '4', '令狐冲', '1', '独孤九剑', '0', '3' );

bug分析:mysql的语法格式,英文符号,分号,变量名称是否正确

增删改查
2022-05-26T03:34:21.png

SELECT * FROM t_book 

INSERT INTO t_book(id, title, pub_date) VALUES ('8', '梦游记', '1999-12-24');
INSERT INTO t_book VALUES('6', '西游记3', '1995-12-24', '2', '80', '0' );

2022-05-26T12:53:41.png

网速好慢哦,等待有点点久

2022-05-26T12:56:53.png