File tree Expand file tree Collapse file tree 4 files changed +24
-8
lines changed Expand file tree Collapse file tree 4 files changed +24
-8
lines changed Original file line number Diff line number Diff line change
1
+ # 這是一個範例檔案,請複製一份 .env.example 並命名為 .env
2
+ # 並將以下的設定值填入
3
+ MYSQL_USER = 資料庫使用者
4
+ MYSQL_PASSWORD = 資料庫使用者密碼
5
+ MYSQL_PORT = 資料庫連接埠
6
+ MYSQL_DATABASE = 資料庫名稱
7
+ HOST = 資料庫主機位址
Original file line number Diff line number Diff line change @@ -12,3 +12,4 @@ read.txt
12
12
nohup.out
13
13
pointLog.out
14
14
flakLog.out
15
+ .env
Original file line number Diff line number Diff line change 1
- # IMPORTANT!!!!Must ignore git!!!
2
1
import mysql .connector
2
+ import os
3
+ from dotenv import load_dotenv
3
4
5
+ load_dotenv (f'{ os .getcwd ()} /.env' )
6
+
7
+
8
+ HOSTIP = os .getenv ('HOST' )
9
+ PORT = os .getenv ('MYSQL_PORT' )
10
+ DBUSER = os .getenv ('MYSQL_USER' )
11
+ DBNAME = os .getenv ('MYSQL_DATABASE' )
12
+ PWD = os .getenv ('MYSQL_PASSWORD' )
4
13
def connect ():
5
- connection = mysql .connector .connect (
6
- host = "" ,
7
- port = "" ,
8
- user = "" ,
9
- passwd = "" ,
10
- database = "" ,
11
- auth_plugin = "mysql_native_password"
14
+ connection = mysql .connector .connect (host = HOSTIP ,
15
+ port = PORT ,
16
+ user = DBUSER ,
17
+ passwd = PWD ,
18
+ database = DBNAME
12
19
)
20
+
13
21
return connection
You can’t perform that action at this time.
0 commit comments