亚洲乱码中文字幕综合,日本午夜免费福利视频,亚洲伊人久久大香线蕉综合图片,77777熟女视频在线观看

13657687333

新聞中心

NEWS

當(dāng)前位置:首頁>建站知識

python開發(fā)網(wǎng)站建設(shè)入門一pymysql鏈接mysql循環(huán)讀取數(shù)據(jù)

發(fā)布日期:2020-12-18 瀏覽量:3116次

利用python鏈接mysql數(shù)據(jù)庫并循環(huán)讀取出里面的數(shù)據(jù)。
1.首先打開vs code,新建一個(gè)helllo.py

2. 輸入以下代碼

import pymysql
# 打開數(shù)據(jù)庫連接
db = pymysql.connect(host='192.168.1.50',
    port=3309,
    user='root',
    password='123456',
    database='webim',
    charset='utf8')
# 使用 cursor() 方法創(chuàng)建一個(gè)游標(biāo)對象 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ù)庫連接
db.close()


3. 執(zhí)行結(jié)果如下:

北京

天津

上海

重慶

銀川

拉薩

南寧

......

地圖導(dǎo)航