import pymysql
# 打開數(shù)據(jù)庫(kù)連接
db = pymysql.connect(host='192.168.1.50',
port=3309,
user='root',
password='123456',
database='webim',
charset='utf8')
# 使用 cursor() 方法創(chuàng)建一個(gè)游標(biāo)對(duì)象 cursor
sql = "select * from tc_webim_city"
cursor = db.cursor(cursor=pymysql.cursors.DictCursor)
cursor.execute(sql)
data = cursor.fetchall()
for row in data:
print(row['city'])
# 關(guān)閉數(shù)據(jù)庫(kù)連接
db.close()
......