添加期末大作业文件夹Project,目前与Assignment5中一致
This commit is contained in:
17
Project/init_db.py
Normal file
17
Project/init_db.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import pymysql
|
||||
|
||||
db = pymysql.connect(
|
||||
host='localhost', user='kejingfan',
|
||||
password='KJF2811879', database='TESTDB'
|
||||
)
|
||||
|
||||
cursor = db.cursor()
|
||||
|
||||
with open('db.sql', 'r') as f:
|
||||
sql_commands = f.read().split(';')
|
||||
for command in sql_commands:
|
||||
if command.strip(): # 确保不执行空命令
|
||||
cursor.execute(command)
|
||||
|
||||
db.close()
|
||||
|
||||
Reference in New Issue
Block a user