程式語言 - Python - v3.x - Connect MySQL



參考資訊:
https://mysqlclient.readthedocs.io/

main.py

import os
import sys
import MySQLdb

DB = 'xxx'
USER = 'xxx'
PASSWD = 'xxx'
IP = 'xxx.xxx.xxx.xxx'

db = MySQLdb.connect(IP, USER, PASSWD, DB, charset='utf8')
cur = db.cursor()

cur.execute('lock table mytable write;')
cur.execute('select * from mytable;')

r = cur.fetchall()

cur.execute('unlock table;')

db.commit()
db.close()