import pymysql
# 打开数据库连接
db = pymysql.connect(host='192.168.1.50',
port=3309,
user='root',
password='123456',
database='webim',
charset='utf8')
# 使用 cursor() 方法创建一个游标对象 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'])
# 关闭数据库连接
db.close()
......