1
0

refactor: import the sql file when the service starts

This commit is contained in:
gin
2026-05-08 15:27:50 +08:00
parent fdae916d12
commit cc20e89161
3 changed files with 35 additions and 4 deletions
+26 -3
View File
@@ -34,8 +34,31 @@ cd backend
docker compose up -d docker compose up -d
``` ```
On a fresh Docker volume, Compose creates the MySQL database `agileboot_pure`. The compose configuration mounts `backend/sql/agileboot.sql` into the MySQL
Import the SQL files under `backend/sql/` before starting the backend. container as `/docker-entrypoint-initdb.d/01-agileboot.sql`.
The official MySQL image only runs files in `/docker-entrypoint-initdb.d` when
the database directory is empty, during the first initialization of the
`mysql_data` volume.
If MySQL has already been started before, the `mysql_data` volume already
contains data and `docker compose up -d` will not import the SQL again. To
reinitialize the local database, remove the volumes first:
```bash
cd backend
docker compose down -v
docker compose up -d
```
Warning: `docker compose down -v` deletes the local MySQL and Redis volumes,
including existing database data and Redis data.
If you do not want to delete the volumes, import the SQL manually:
```bash
cd backend
docker exec -i mysql-server mysql -uroot -proot123 agileboot_pure < sql/agileboot.sql
```
### Install Frontend Dependencies ### Install Frontend Dependencies
@@ -50,7 +73,7 @@ Start the backend:
```bash ```bash
cd backend cd backend
./mvnw -pl agileboot-admin -am spring-boot:run ./mvnw -pl agileboot-admin spring-boot:run
``` ```
Start the web frontend: Start the web frontend:
+4
View File
@@ -3,6 +3,9 @@ services:
image: mysql:8.0 image: mysql:8.0
container_name: mysql-server container_name: mysql-server
restart: always restart: always
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
environment: environment:
MYSQL_ROOT_PASSWORD: root123 MYSQL_ROOT_PASSWORD: root123
MYSQL_DATABASE: agileboot_pure MYSQL_DATABASE: agileboot_pure
@@ -10,6 +13,7 @@ services:
- "3306:3306" - "3306:3306"
volumes: volumes:
- mysql_data:/var/lib/mysql - mysql_data:/var/lib/mysql
- ./sql/agileboot.sql:/docker-entrypoint-initdb.d/01-agileboot.sql:ro
networks: networks:
- db-network - db-network
@@ -1,3 +1,8 @@
SET NAMES utf8mb4;
SET character_set_client = utf8mb4;
SET character_set_connection = utf8mb4;
SET character_set_results = utf8mb4;
create table sys_config create table sys_config
( (
config_id int auto_increment comment '参数主键' config_id int auto_increment comment '参数主键'
@@ -359,4 +364,3 @@ create table sys_user
INSERT INTO sys_user (user_id, post_id, role_id, dept_id, username, nickname, user_type, email, phone_number, sex, avatar, password, status, login_ip, login_date, is_admin, creator_id, create_time, updater_id, update_time, remark, deleted) VALUES (1, 1, 1, 4, 'admin', 'valarchie1', 0, 'agileboot@163.com', '15888888883', 0, '/profile/avatar/20230725164110_blob_6b7a989b1cdd4dd396665d2cfd2addc5.png', '$2a$10$o55UFZAtyWnDpRV6dvQe8.c/MjlFacC49ASj2usNXm9BY74SYI/uG', 1, '127.0.0.1', '2023-08-14 23:07:03', 1, null, '2022-05-21 08:30:54', 1, '2023-08-14 23:07:03', '管理员', 0); INSERT INTO sys_user (user_id, post_id, role_id, dept_id, username, nickname, user_type, email, phone_number, sex, avatar, password, status, login_ip, login_date, is_admin, creator_id, create_time, updater_id, update_time, remark, deleted) VALUES (1, 1, 1, 4, 'admin', 'valarchie1', 0, 'agileboot@163.com', '15888888883', 0, '/profile/avatar/20230725164110_blob_6b7a989b1cdd4dd396665d2cfd2addc5.png', '$2a$10$o55UFZAtyWnDpRV6dvQe8.c/MjlFacC49ASj2usNXm9BY74SYI/uG', 1, '127.0.0.1', '2023-08-14 23:07:03', 1, null, '2022-05-21 08:30:54', 1, '2023-08-14 23:07:03', '管理员', 0);
INSERT INTO sys_user (user_id, post_id, role_id, dept_id, username, nickname, user_type, email, phone_number, sex, avatar, password, status, login_ip, login_date, is_admin, creator_id, create_time, updater_id, update_time, remark, deleted) VALUES (2, 2, 2, 5, 'ag1', 'valarchie2', 0, 'agileboot1@qq.com', '15666666666', 1, '/profile/avatar/20230725114818_avatar_b5bf400732bb43369b4df58802049b22.png', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', 1, '127.0.0.1', '2022-05-21 08:30:54', 0, null, '2022-05-21 08:30:54', null, null, '测试员1', 0); INSERT INTO sys_user (user_id, post_id, role_id, dept_id, username, nickname, user_type, email, phone_number, sex, avatar, password, status, login_ip, login_date, is_admin, creator_id, create_time, updater_id, update_time, remark, deleted) VALUES (2, 2, 2, 5, 'ag1', 'valarchie2', 0, 'agileboot1@qq.com', '15666666666', 1, '/profile/avatar/20230725114818_avatar_b5bf400732bb43369b4df58802049b22.png', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', 1, '127.0.0.1', '2022-05-21 08:30:54', 0, null, '2022-05-21 08:30:54', null, null, '测试员1', 0);
INSERT INTO sys_user (user_id, post_id, role_id, dept_id, username, nickname, user_type, email, phone_number, sex, avatar, password, status, login_ip, login_date, is_admin, creator_id, create_time, updater_id, update_time, remark, deleted) VALUES (3, 2, 0, 5, 'ag2', 'valarchie3', 0, 'agileboot2@qq.com', '15666666667', 1, '/profile/avatar/20230725114818_avatar_b5bf400732bb43369b4df58802049b22.png', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', 1, '127.0.0.1', '2022-05-21 08:30:54', 0, null, '2022-05-21 08:30:54', null, null, '测试员2', 0); INSERT INTO sys_user (user_id, post_id, role_id, dept_id, username, nickname, user_type, email, phone_number, sex, avatar, password, status, login_ip, login_date, is_admin, creator_id, create_time, updater_id, update_time, remark, deleted) VALUES (3, 2, 0, 5, 'ag2', 'valarchie3', 0, 'agileboot2@qq.com', '15666666667', 1, '/profile/avatar/20230725114818_avatar_b5bf400732bb43369b4df58802049b22.png', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', 1, '127.0.0.1', '2022-05-21 08:30:54', 0, null, '2022-05-21 08:30:54', null, null, '测试员2', 0);