Files

30 lines
1.3 KiB
SQL
Raw Permalink 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.
-- init.sql
-- 首次部署时先执行这个脚本建库/建账号,再跑 python init_db.py
--
-- mysql -u root -p < init.sql
--
-- 为什么单独一个文件:
-- SQLAlchemy 的 create_all() 只会建表,不会建 database。
-- 很多人第一次跑报「Unknown database 'student_management_system'」,
-- 就是因为漏了这一步。
--
-- 字符集必须是 utf8mb4:
-- utf8(3 字节)存不下 emoji,也存不下部分生僻字。
-- 学生姓名、籍贯里出现这类字符时,用 utf8 会直接报
-- 「Incorrect string value」而整条插入失败。
CREATE DATABASE IF NOT EXISTS `student_management_system`
DEFAULT CHARACTER SET utf8mb4
DEFAULT COLLATE utf8mb4_0900_ai_ci;
-- 可选:给应用单独建一个低权限账号,不要用 root 连业务库。
-- 生产环境尤其重要 —— root 权限过大,一旦应用被注入损失无法控制。
-- CREATE USER IF NOT EXISTS 'sms_app'@'%' IDENTIFIED BY '换成你自己的密码';
-- GRANT SELECT, INSERT, UPDATE, DELETE ON `student_management_system`.* TO 'sms_app'@'%';
-- FLUSH PRIVILEGES;
-- 建完库之后:
-- 1. 把 .env.example 复制成 .env,填上 DB_USER / DB_PASSWORD
-- 2. python init_db.py --seed 建表 + 灌演示数据
-- 3. python main.py 启动服务(默认 http://127.0.0.1:8004)