特级做A爰片毛片免费看108,四虎澳门高清在线观看,GOGOGO免费高清日本TV,国产精品久久久久久久久久免费看

13657687333

新聞中心

NEWS

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

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

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

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

2. 輸入以下代碼

import pymysql
# 打開(kāi)數(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()


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

北京

天津

上海

重慶

銀川

拉薩

南寧

......

地圖導(dǎo)航