mysql之基本常用的语法

Source

1.增加数据

insert into
1.指定列插入
语法insert into table_name(列名1,列名2,....,列名n) values (值1,值2,...,值n),(值1,值2,...,值n),....,(值1,值2,...,值n);
2.全部列插入
语法insert into tablename values (值1,值2,...,值n),(值1,值2,...,值n),....,(值1,值2,...,值n);

示例:

-- 指定列名插入
insert into test_user(user_id,user_name,nick_name)
values
(1,'mytest1','测试账号1'),
(2,'mytest2','测试账号2');
-- 不指定列,直接插入所以列的值
insert into test_user 
values
(3,1,'mytest3','测试账号3','1','3030@qq.com','18512345678','0','12345678','0','测试'),
(4,1,'mytest4','测试账号4','1','3031@qq.com','18512345679','0','12345678','0','测试1');

在这里插入图片描述

注意:插入数据时,需要注意插入的值和对应列的字段类型需要保持一致;

2.删除数据

delete
语法

delete from table_name;

delete from table_name
where 条件;

示例:

-- 删除指定条件的数据
delete from test_user
where user_name = 'mytest1';
-- 删除指定表中所有数据
delete from test_user;

在这里插入图片描述

注意:不带where时,会把表中所有的数据都删掉,带where只会删除满足条件的数据;

3.更新/修改数据

update
语法

update table_name
set 字段名1 =1, ....,字段名n = 值n
where 条件;

update table_name
set 字段名1 =1, ....,字段名n = 值n

示例:

-- 不带where更新指定表中,字段所有的值
update test_user
set dept_id = 2;
-- 带where更新满足条件的数据
update test_user
set dept_id = 4,user_type = 0, nick_name = '测试账号3333'
where user_name = 'mytest3';

在这里插入图片描述

4.查询数据

select
语法

-- 查询后展示指定的字段;
select 字段名1,....,字段名n from table_name

-- 查询后展示全部字段;
select * from table_name

示例:

select user_id user_name,nick_name from test_user;
select * from test_user;

4.1.where子句

在select的基础上加上条件,进行条件筛选,查询满足条件的数据;
语法

select 字段1,....,字段n from table_name
where 条件;

示例:

-- 查询user_id=1的数据,展示全部字段;
select * from test_user
where user_id = 1;

常用的条件运算符:
=:等于;
!=:不等于;
>:大于;
<:小于;
<=:小于等于;
>=:大于等于;
between…and …:在两值之间;
not between:不在两值之间;
in:在集合中;
not in:不在集合中;
like:模糊匹配;
is null:为空;
is not null:不为空;
and:条件组合和;
or:条件组合或;

示例:between…and

-- 查询user_id在1-3之间的
select * from test_user
where user_id between 1 and 3;

示例:not between

-- 查询user_id不在1-3之间的
select * from test_user
where user_id not between 1 and 3;

示例:in

-- 查询user_id是1、3、4的
select * from test_user
where user_id  in(1,3,4);

示例:not in

-- 查询user_id不是1、3、4的
select * from test_user
where user_id not in(1,3,4);

示例:like

-- 模糊查询user_name
select * from test_user
-- user_name以my开头的
-- where user_name like 'my%' ;

-- user_name包含test的
-- where user_name like '%test%' ;

-- user_name以test1结尾的
where user_name like '%test1' ;

示例:is null

-- email是null的
select * from test_user
where email is null;

示例:is not null

-- email不是null的
select * from test_user
where email is not null;

示例:and

-- 查询user_id=1且,dept_id = 1的
select * from test_user
where user_id =1 and dept_id = 1 ;

示例:or

-- 查询user_id=1或者,dept_id = 2的
select * from test_user 
where user_id =1 or dept_id = 2 ;

4.2.order by

对数据排序
语法
order by 字段名1,...字段名n desc;

order by 字段名1,...字段名n asc;
示例:desc – 降序

select * from test_menu
order by menu_id desc;

示例:asc – 升序

-- 默认asc排序
select * from test_menu
order by menu_id asc;

4.3.limit与offset

limit:返回指定的行数;
offset:与limit结合起来使用,跳过指定的行数;
语法
limit 行数

limit 行数 offset 行数

示例:

-- 返回数据前3条;
select * from test_menu
limit 3;

-- 跳过返回的前3条数据;
select * from test_menu
limit 3 offset 7;

-- 可以结合起来使用,menu_id倒序,跳过前7条数据后,返回前三条
select * from test_menu
order by menu_id desc
limit 3 offset 7;

4.4.分组与having

group by:分组,通常与聚合函数一起使用,对每个分组进行计算
having:过滤分组后的数据
语法

select 列名1,....列名n,function(列名) from table_name
group by 列名1,....列名n
having 条件

示例:

-- 加上having则查询:角色id为1的关联的菜单总数;
select role_id,count(menu_id) from test_role_menu
group by role_id
having role_id = 1

-- 不加having:查询每个角色id,关联的菜单总数
select role_id,count(menu_id) from test_role_menu
group by role_id

常用的聚合函数
SUM:求和
AVG:求平均值
COUNT:求总数
MIN:求最小值
MAX:求最大值

4.5.连接

left join ... no
左连接,左表返回所有记录,右表返回满足条件的记录;
语法

select 字段1,...,字段n from table_name1
left join table_name2 no 条件;

示例:

-- 连接test_role和test_role_menu表,查询每个role_id的关联菜单总数,左表数据全部返回
select role_name,coun_role.coun from test_role
left join 
(select role_id,count(menu_id) as coun from test_role_menu
group by role_id) as coun_role
on coun_role.role_id = test_role.role_id;

right join....no
右连接,右表返回所有记录,左表返回满足条件的记录;
语法

select 字段1,...,字段n from table_name1
right join table_name2 no 条件;

示例:

-- 连接test_role和test_role_menu表,查询每个role_id的关联菜单总数,右表数据全部返回
select role_name,coun_role.coun from test_role
right join 
(select role_id,count(menu_id) as coun from test_role_menu
group by role_id) as coun_role
on coun_role.role_id = test_role.role_id;

inner join....no
内连接,返回满足连接条件的记录;
语法

select 字段1,...,字段n from table_name1
inner join table_name2 no 条件;

示例:

-- 连接test_role和test_role_menu表,查询每个test_role.role_id=test_role_menu.role_id,
-- 即:角色关联了菜单的,菜单总数
select role_name,coun_role.coun from test_role
inner join 
(select role_id,count(menu_id) as coun from test_role_menu
group by role_id) as coun_role
on coun_role.role_id = test_role.role_id;

如图:在这里插入图片描述

5.创建表

create table
语法

create table table_name (
	字段名1  类型(长度)  约束,
	...., 
	字段名n  类型(长度)  约束, 
	primary key (字段名1,...,字段名n) 
);

提示:约束是可选的,根据实际情况的需要决定是否需要加;常见的有:
not null:非空约束,指示某列不能存储 null值;
unique:唯一约束,保证某列的每行必须有唯一的值;
primary key:主键约束,not null 和unique的结合,确保某列有唯一标识;
foreign key:外键约束,保证参照完整性,一个表中的数据匹配另一个表中的值;
check:检查约束,保证列中的值符合指定的条件;
default:设置默认值,没有给列赋值时的默认值;
comment:是注释,可以理解为写个备注描述字段是干什么的,我这里为了演示加上了

示例:

create table test_user(
	user_id bigint(20) not null auto_increment comment '用户id',
	dept_id bigint(20) comment '部门id',
	user_name varchar(30) not null comment '用户账号',
	nick_name varchar(30) not null comment '用户昵称',
	user_type varchar(2) comment '用户类型',
	email varchar(50) COMMENT '用户邮箱',
	phonenumber varchar(11) COMMENT '手机号码',
	sex char(1) COMMENT '用户性别',
	password varchar(100) COMMENT '密码',
	status char(1) COMMENT '帐号状态',
	remark varchar(500) COMMENT '备注',
	primary key (user_id)
);

在这里插入图片描述

相关表和数据:

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for test_dept
-- ----------------------------
DROP TABLE IF EXISTS `test_dept`;
CREATE TABLE `test_dept`  (
  `dept_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '部门id',
  `parent_id` bigint(20) NULL DEFAULT 0 COMMENT '父部门id',
  `ancestors` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '祖级列表',
  `dept_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '部门名称',
  `order_num` int(4) NULL DEFAULT 0 COMMENT '显示顺序',
  `leader` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '负责人',
  `phone` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '联系电话',
  `email` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '邮箱',
  `status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '0' COMMENT '部门状态(0正常 1停用)',
  `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
  PRIMARY KEY (`dept_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '部门表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of test_dept
-- ----------------------------
INSERT INTO `test_dept` VALUES (1, 0, '0', '测试管理系统', 0, 'admin', '15888888888', '15888888888@qq.com', '0', 'admin');
INSERT INTO `test_dept` VALUES (2, 1, '1', '校长室', 1, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (3, 1, '1', '办公室', 2, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (4, 1, '1', '教导处', 3, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (5, 1, '1', '德育处', 4, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (6, 1, '1', '财务室', 5, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (7, 1, '1', '科研室', 6, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (8, 1, '1', '工会室', 7, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (9, 1, '1', '文化及新媒体中心', 8, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (10, 1, '1', '医务室', 9, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (11, 1, '1', '后勤室', 10, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (12, 1, '1', '幼儿园', 11, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (13, 1, '1', '驾驶员', 12, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (14, 1, '1', '测试部', 10, 'admin', NULL, NULL, NULL, NULL);
INSERT INTO `test_dept` VALUES (15, 1, '1', '测试部门', 99, 'admin', NULL, NULL, NULL, NULL);

-- ----------------------------
-- Table structure for test_menu
-- ----------------------------
DROP TABLE IF EXISTS `test_menu`;
CREATE TABLE `test_menu`  (
  `menu_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '菜单ID',
  `menu_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '菜单名称',
  `parent_id` bigint(20) NULL DEFAULT 0 COMMENT '父菜单ID',
  `order_num` int(4) NULL DEFAULT 0 COMMENT '显示顺序',
  `path` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '路由地址',
  `component` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '组件路径',
  `is_frame` int(1) NULL DEFAULT 1 COMMENT '是否为外链(0是 1否)',
  `is_cache` int(1) NULL DEFAULT 0 COMMENT '是否缓存(0缓存 1不缓存)',
  `menu_type` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '菜单类型(M目录 C菜单 F按钮)',
  `visible` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '0' COMMENT '菜单状态(0显示 1隐藏)',
  `status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '0' COMMENT '菜单状态(0正常 1停用)',
  `perms` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '权限标识',
  PRIMARY KEY (`menu_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 21 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '菜单权限表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of test_menu
-- ----------------------------
INSERT INTO `test_menu` VALUES (1, '系统管理', 0, 7, 'system', NULL, 1, 0, 'M', '0', '0', '');
INSERT INTO `test_menu` VALUES (2, '系统监控', 0, 8, 'monitor', NULL, 1, 0, 'M', '0', '0', '');
INSERT INTO `test_menu` VALUES (3, '系统工具', 0, 9, 'tool', NULL, 1, 0, 'M', '0', '0', '');
INSERT INTO `test_menu` VALUES (4, '用户管理', 0, 1, 'users', 'system/user/index', 1, 1, 'C', '0', '0', 'system:user:list');
INSERT INTO `test_menu` VALUES (5, '角色管理', 0, 2, 'role', 'system/role/index', 1, 0, 'C', '0', '0', 'system:role:list');
INSERT INTO `test_menu` VALUES (6, '菜单管理', 1, 3, 'menu', 'system/menu/index', 1, 0, 'C', '0', '0', 'system:menu:list');
INSERT INTO `test_menu` VALUES (7, '部门管理', 0, 2, 'dept', 'system/dept/index', 1, 0, 'C', '0', '0', 'system:dept:list');
INSERT INTO `test_menu` VALUES (8, '岗位管理', 1, 5, 'post', 'system/post/index', 1, 0, 'C', '0', '0', 'system:post:list');
INSERT INTO `test_menu` VALUES (9, '字典管理', 1, 6, 'dict', 'system/dict/index', 1, 0, 'C', '0', '0', 'system:dict:list');
INSERT INTO `test_menu` VALUES (10, '参数设置', 1, 7, 'config', 'system/config/index', 1, 0, 'C', '0', '0', 'system:config:list');
INSERT INTO `test_menu` VALUES (11, '学习资料', 0, 3, 'notice', 'system/notice/index', 1, 0, 'C', '0', '0', 'system:notice:list');
INSERT INTO `test_menu` VALUES (12, '日志管理', 1, 9, 'log', '', 1, 0, 'M', '0', '0', '');
INSERT INTO `test_menu` VALUES (13, '操作日志', 0, 1, 'operlog', 'system/operlog/index', 1, 0, 'C', '0', '0', 'system:operlog:list');
INSERT INTO `test_menu` VALUES (14, '登录日志', 0, 2, 'logininfor', 'system/logininfor/index', 1, 0, 'C', '0', '0', 'system:logininfor:list');
INSERT INTO `test_menu` VALUES (15, '用户查询', 1, 1, 'user', '', 1, 0, 'F', '0', '0', 'system:user:query');
INSERT INTO `test_menu` VALUES (16, '用户新增', 1, 2, 'useradd', '', 1, 0, 'F', '0', '0', 'system:user:add');
INSERT INTO `test_menu` VALUES (17, '用户修改', 1, 3, 'userupdate', '', 1, 0, 'F', '0', '0', 'system:user:edit');
INSERT INTO `test_menu` VALUES (18, '用户删除', 1, 4, 'userdelete', '', 1, 0, 'F', '0', '0', 'system:user:remove');
INSERT INTO `test_menu` VALUES (19, '用户导出', 1, 5, 'useroutfile', '', 1, 0, 'F', '0', '0', 'system:user:export');
INSERT INTO `test_menu` VALUES (20, '用户导入', 1, 6, 'userinfile', '', 1, 0, 'F', '0', '0', 'system:user:import');

-- ----------------------------
-- Table structure for test_role
-- ----------------------------
DROP TABLE IF EXISTS `test_role`;
CREATE TABLE `test_role`  (
  `role_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '角色ID',
  `role_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '角色名称',
  `role_key` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '角色权限字符串',
  `role_sort` int(4) NOT NULL COMMENT '显示顺序',
  `data_scope` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '1' COMMENT '数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)',
  `menu_check_strictly` tinyint(1) NULL DEFAULT 1 COMMENT '菜单树选择项是否关联显示',
  `dept_check_strictly` tinyint(1) NULL DEFAULT 1 COMMENT '部门树选择项是否关联显示',
  `status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '角色状态(0正常 1停用)',
  `del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
  `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
  `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
  `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`role_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 12 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '角色信息表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of test_role
-- ----------------------------
INSERT INTO `test_role` VALUES (1, '超级管理员', 'admin', 1, '1', 1, 1, '0', '0', 'admin', '2024-01-23 05:17:39', '', NULL, '超级管理员');
INSERT INTO `test_role` VALUES (2, '普通角色', 'common', 2, '1', 1, 1, '0', '2', 'admin', '2024-01-23 05:17:39', 'admin', '2024-10-11 15:03:25', '普通角色');
INSERT INTO `test_role` VALUES (3, '办公室角色', 'docAdmin', 3, '1', 1, 1, '0', '2', 'admin', '2024-02-06 09:41:48', 'admin', '2024-02-06 09:44:21', NULL);
INSERT INTO `test_role` VALUES (4, '教导处角色', 'docApply', 4, '1', 1, 1, '0', '0', 'admin', '2024-02-06 09:44:12', 'admin', '2024-10-11 15:06:06', NULL);
INSERT INTO `test_role` VALUES (5, '德育处角色', 'docTransfer', 5, '1', 1, 1, '0', '0', 'admin', '2024-02-06 09:44:56', 'admin', '2024-11-08 11:49:27', NULL);
INSERT INTO `test_role` VALUES (6, '财务室角色', 'committee', 0, '1', 1, 1, '0', '0', 'admin', '2024-10-11 15:46:23', 'admin', '2024-10-24 17:52:21', NULL);
INSERT INTO `test_role` VALUES (7, '科研室角色', 'administration', 0, '1', 1, 1, '0', '0', 'admin', '2024-10-11 15:47:02', 'admin', '2024-10-24 17:52:39', NULL);
INSERT INTO `test_role` VALUES (8, '行政会角色', 'administration', 0, '1', 1, 1, '0', '2', 'admin', '2024-10-11 15:47:02', '', NULL, NULL);
INSERT INTO `test_role` VALUES (9, '校长会角色', 'school', 0, '1', 1, 1, '0', '0', 'admin', '2024-10-11 15:48:00', 'admin', '2024-10-28 10:22:03', NULL);
INSERT INTO `test_role` VALUES (10, '医务室角色', 'meetingAdmin', 5, '1', 1, 1, '0', '2', 'admin', '2024-10-11 15:48:34', '', NULL, NULL);
INSERT INTO `test_role` VALUES (11, '后勤角色', 'meetingManager', 0, '1', 1, 1, '0', '0', 'admin', '2024-10-11 15:48:40', 'admin', '2024-11-08 09:56:46', NULL);

-- ----------------------------
-- Table structure for test_role_menu
-- ----------------------------
DROP TABLE IF EXISTS `test_role_menu`;
CREATE TABLE `test_role_menu`  (
  `role_id` bigint(20) NOT NULL COMMENT '角色ID',
  `menu_id` bigint(20) NOT NULL COMMENT '菜单ID',
  PRIMARY KEY (`role_id`, `menu_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '角色和菜单关联表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of test_role_menu
-- ----------------------------
INSERT INTO `test_role_menu` VALUES (1, 1);
INSERT INTO `test_role_menu` VALUES (1, 2);
INSERT INTO `test_role_menu` VALUES (1, 3);
INSERT INTO `test_role_menu` VALUES (1, 4);
INSERT INTO `test_role_menu` VALUES (1, 5);
INSERT INTO `test_role_menu` VALUES (1, 6);
INSERT INTO `test_role_menu` VALUES (1, 7);
INSERT INTO `test_role_menu` VALUES (2, 1);
INSERT INTO `test_role_menu` VALUES (2, 2);
INSERT INTO `test_role_menu` VALUES (4, 4);
INSERT INTO `test_role_menu` VALUES (4, 5);
INSERT INTO `test_role_menu` VALUES (5, 8);
INSERT INTO `test_role_menu` VALUES (20, 10);

-- ----------------------------
-- Table structure for test_user
-- ----------------------------
DROP TABLE IF EXISTS `test_user`;
CREATE TABLE `test_user`  (
  `user_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用户id',
  `dept_id` bigint(20) NULL DEFAULT NULL COMMENT '部门id',
  `user_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '用户账号',
  `nick_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '用户昵称',
  `user_type` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '用户类型',
  `email` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '用户邮箱',
  `phonenumber` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '手机号码',
  `sex` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '用户性别',
  `password` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '密码',
  `status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '帐号状态',
  `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`user_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of test_user
-- ----------------------------
INSERT INTO `test_user` VALUES (1, 1, 'mytest1', '测试账号1', '0', NULL, '18512315678', '1', '12345678', '1', '测试2');
INSERT INTO `test_user` VALUES (2, 2, 'mytest2', '测试账号2', '1', 'test@162.com', '18592345678', '1', '812345678', '1', '测试3');
INSERT INTO `test_user` VALUES (3, 3, 'mytest3', '测试账号3333', '0', '3030@qq.com', '18512345678', '0', '12345678', '0', '测试4');
INSERT INTO `test_user` VALUES (4, 2, 'mytest4', '测试账号4', '1', '3031@qq.com', '18512345679', '0', '12345678', '0', '测试1');

-- ----------------------------
-- Table structure for test_user_role
-- ----------------------------
DROP TABLE IF EXISTS `test_user_role`;
CREATE TABLE `test_user_role`  (
  `user_id` bigint(20) NOT NULL COMMENT '用户ID',
  `role_id` bigint(20) NOT NULL COMMENT '角色ID',
  PRIMARY KEY (`user_id`, `role_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '用户和角色关联表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of test_user_role
-- ----------------------------
INSERT INTO `test_user_role` VALUES (1, 1);
INSERT INTO `test_user_role` VALUES (1, 2);
INSERT INTO `test_user_role` VALUES (1, 3);
INSERT INTO `test_user_role` VALUES (1, 4);
INSERT INTO `test_user_role` VALUES (2, 1);
INSERT INTO `test_user_role` VALUES (2, 3);
INSERT INTO `test_user_role` VALUES (2, 4);

SET FOREIGN_KEY_CHECKS = 1;