Skip to content

Commit a456993

Browse files
authored
修复MySQL连接
1 parent 475802b commit a456993

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

docker-compose.yml

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,17 @@ services:
99
- USE_REDIS=1
1010
- REDIS_HOST=redis
1111
- REDIS_PORT=6379
12-
# ========== MySQL Configuration (uncomment to enable) ==========
13-
# - DB_HOST=mysql
14-
# - DB_PORT=3306
15-
# - DB_USER=root
16-
# - DB_PASSWORD=ms_oauth2api_root
17-
# - DB_DATABASE=ms_oauth2api
18-
# - DB_WAIT_FOR_CONNECTIONS=true
19-
# - DB_CONNECTION_LIMIT=10
20-
# - DB_QUEUE_LIMIT=0
12+
## ===== MySQL Config (uncomment below lines to enable) =====
13+
#- DB_HOST=mysql
14+
#- DB_PORT=3306
15+
#- DB_USER=root
16+
#- DB_PASSWORD=ms_oauth2api_root
17+
#- DB_DATABASE=ms_oauth2api
18+
#- DB_WAIT_FOR_CONNECTIONS=true
19+
#- DB_CONNECTION_LIMIT=10
2120
depends_on:
22-
redis:
23-
condition: service_healthy
24-
# ========== Uncomment below to wait for MySQL ==========
25-
# mysql:
26-
# condition: service_healthy
21+
- redis
22+
#- mysql
2723
restart: unless-stopped
2824
networks:
2925
- app-network
@@ -50,33 +46,33 @@ services:
5046
- redis_data:/data
5147
command: redis-server --appendonly yes
5248

53-
# ========== MySQL Service (uncomment entire block to enable) ==========
54-
# mysql:
55-
# image: mysql:8.0
56-
# ports:
57-
# - "13306:3306"
58-
# environment:
59-
# - MYSQL_ROOT_PASSWORD=ms_oauth2api_root
60-
# - MYSQL_DATABASE=ms_oauth2api
61-
# - MYSQL_CHARACTER_SET_SERVER=utf8mb4
62-
# - MYSQL_COLLATION_SERVER=utf8mb4_unicode_ci
63-
# restart: unless-stopped
64-
# networks:
65-
# - app-network
66-
# healthcheck:
67-
# test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-pms_oauth2api_root"]
68-
# interval: 10s
69-
# timeout: 5s
70-
# retries: 10
71-
# start_period: 30s
72-
# volumes:
73-
# - mysql_data:/var/lib/mysql
74-
# command: --default-authentication-plugin=mysql_native_password
49+
## ===== MySQL Service (uncomment below to enable) =====
50+
#mysql:
51+
# image: mysql:8.0
52+
# ports:
53+
# - "13306:3306"
54+
# environment:
55+
# - MYSQL_ROOT_PASSWORD=ms_oauth2api_root
56+
# - MYSQL_DATABASE=ms_oauth2api
57+
# - MYSQL_CHARACTER_SET_SERVER=utf8mb4
58+
# - MYSQL_COLLATION_SERVER=utf8mb4_unicode_ci
59+
# restart: unless-stopped
60+
# networks:
61+
# - app-network
62+
# healthcheck:
63+
# test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-pms_oauth2api_root"]
64+
# interval: 10s
65+
# timeout: 5s
66+
# retries: 10
67+
# start_period: 30s
68+
# volumes:
69+
# - mysql_data:/var/lib/mysql
70+
# command: --default-authentication-plugin=mysql_native_password
7571

7672
networks:
7773
app-network:
7874
driver: bridge
7975

8076
volumes:
8177
redis_data:
82-
# mysql_data:
78+
#mysql_data:

main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const config = require('./config')
1313
const logger = require('./utils/logger')
1414
app.use(require('./middlewares/logger'))
1515

16+
// 初始化数据库连接(如果配置了的话)
17+
require('./utils/db')
18+
1619
// 错误处理
1720
const errorHandler = require('./middlewares/error')
1821
app.use(errorHandler)

0 commit comments

Comments
 (0)