import pymysql
config = { 'host': 'xxx.xx.xx.xxx', 'user': 'xxxx', 'pw': 'xxxxx', 'dbname': 'xxxxx' }
# 數據庫連接 db = pymysql.connect(config['host'], config['user'], config['pw'], config['dbname'], charset='utf8') # 創建遊標,通過連接與數據通信 cursor = db.cursor()
# 執行查詢
cursor.execute("SELECT * FROM table_a")
# 使用結束後關閉連接
db.close()