pymysql鏈接

import pymysql

conn=pymysql.connect(host='localhost',user='root',password='123',db='sg',charset='utf8')
                       #先修路-conn

car = conn.cursor()    #備車-car

sql = "select * from sanguo"    #裝貨

car.execute(sql)        #發車

conn.commit()           #插入內容要提交 mit

emps = car.fetchall()      #帶回交易貨物

for i in emps:
    print(i)    #查貨


'''
(1, '呂布', 32, '方天畫戟', '羣雄', '魔神降世')
(2, '趙雲', 46, '龍膽', '蜀國', '天翔之龍')
(3, '曹操', 50, '百辟刀', '魏國', '霸道之刃')
(4, '夏侯惇', 15, '也是刀', '魏國', '無極之刃')
(5, '小喬', 18, '扇子', '吳國', '星華繚亂')
(6, '大喬', 19, '燈籠', '吳國', '魔神降世')
(7, '孫尚香', 28, '方天畫戟', '羣雄', '魔神降世')
'''
相關文章
相關標籤/搜索