python 的DB連接

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()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章