【原創】python3讀取mysql數據庫

01.環境準備

使用的包:pymysql

pymysql下載地址:

點擊打開鏈接

02.pymysql安裝:

https://blog.csdn.net/u013952400/article/details/80432452

03.示例代碼:

# -*- coding:utf-8 -*-
# __author__ = "LJY"
import pymysql

conn = pymysql.connect(host='192.168.10.101', port=3306, user='root', passwd='root', db='python_operation_01')
cursor = conn.cursor()
cursor.execute("select * from demo_pic_repo")

# 獲取剩餘結果的第一行數據
row_1 = cursor.fetchone()
print(row_1)
# 獲取剩餘結果前n行數據
# row_2 = cursor.fetchmany(3)

# 獲取剩餘結果所有數據
# row_3 = cursor.fetchall()

conn.commit()
cursor.close()
conn.close()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章