Files
schoolNews/schoolNewsServ/.bin/mysql/sql/createTableUser.sql
2025-10-05 18:00:29 +08:00

68 lines
3.4 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use school_news;
-- MySQL Script to create the user table
DROP TABLE IF EXISTS `tb_sys_user`;
CREATE TABLE `tb_sys_user` (
`id` VARCHAR(50) NOT NULL COMMENT '用户ID',
`username` VARCHAR(50) NOT NULL COMMENT '用户名',
`password` VARCHAR(128) NOT NULL COMMENT '密码(建议存储 bcrypt/argon2 哈希)',
`email` VARCHAR(100) DEFAULT NULL COMMENT '电子邮件',
`phone` VARCHAR(20) DEFAULT NULL COMMENT '电话号码',
`wechat_id` VARCHAR(50) DEFAULT NULL COMMENT '微信ID',
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
`status` INT(4) NOT NULL DEFAULT 1 COMMENT '状态',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_user_username` (`username`),
UNIQUE KEY `uk_user_email` (`email`),
KEY `idx_user_phone` (`phone`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
-- 推荐:把默认 admin 密码替换为已哈希的值
INSERT INTO `tb_sys_user` (id, username, password, email) VALUES
('1', 'admin', '123456', '3223905473@qq.com');
-- 用户信息表
DROP TABLE IF EXISTS `tb_sys_user_info`;
CREATE TABLE `tb_sys_user_info` (
`id` VARCHAR(50) NOT NULL COMMENT '用户信息ID',
`user_id` VARCHAR(50) NOT NULL COMMENT '用户ID',
`avatar` VARCHAR(255) DEFAULT NULL COMMENT '头像',
`gender` INT(4) DEFAULT 0 COMMENT '性别',
`family_name` VARCHAR(50) DEFAULT NULL COMMENT '',
`given_name` VARCHAR(50) DEFAULT NULL COMMENT '',
`full_name` VARCHAR(100) DEFAULT NULL COMMENT '全名',
`id_card` VARCHAR(50) DEFAULT NULL COMMENT '身份证号',
`address` VARCHAR(255) DEFAULT NULL COMMENT '地址',
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_user_info_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO `tb_sys_user_info` (id, user_id, full_name) VALUES ('1', '1', '管理员');
DROP TABLE IF EXISTS `tb_sys_login_log`;
CREATE TABLE `tb_sys_login_log` (
`id` VARCHAR(50) NOT NULL COMMENT '登录日志ID',
`user_id` VARCHAR(50) NOT NULL COMMENT '用户ID',
`username` VARCHAR(50) NOT NULL COMMENT '用户名',
`ip_address` VARCHAR(45) DEFAULT NULL COMMENT 'IP地址',
`ip_source` VARCHAR(100) DEFAULT NULL COMMENT 'IP来源',
`browser` VARCHAR(100) DEFAULT NULL COMMENT '浏览器',
`os` VARCHAR(100) DEFAULT NULL COMMENT '操作系统',
`password` VARCHAR(100) DEFAULT NULL COMMENT '密码',
`login_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '登录时间',
`status` INT(4) DEFAULT 1 COMMENT '登录状态0失败 1成功',
`error_count` INT(4) DEFAULT 0 COMMENT '错误次数',
`message` VARCHAR(255) DEFAULT NULL COMMENT '登录消息',
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`),
index `idx_user_id` (`user_id`) USING BTREE,
index `idx_login_time` (`login_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;