python读取mysql数据_如何将mysql的数据读取python
展開全部
本文實(shí)例為大家2113分享了Python讀取MySQL數(shù)據(jù)庫(kù)表數(shù)據(jù)的具體代碼,5261供大家參考,具體內(nèi)容4102如下
環(huán)境:Python 3.6 ,Window 64bit
目的:1653從MySQL數(shù)據(jù)庫(kù)讀取目標(biāo)表數(shù)據(jù),并處理
代碼:
# -*- coding: utf-8 -*-
import pandas as pd
import pymysql
## 加上字符集參數(shù),防止中文亂碼
dbconn=pymysql.connect(
host="**********",
database="kimbo",
user="kimbo_test",
password="******",
port=3306,
charset='utf8'
)
#sql語句
sqlcmd="select col_name,col_type,col_desc from itf_datadic_dtl_d limit 10"
#利用pandas 模塊導(dǎo)入mysql數(shù)據(jù)
a=pd.read_sql(sqlcmd,dbconn)
#取前5行數(shù)據(jù)
b=a.head()
print(b)
# 讀取csv數(shù)據(jù)
# pd.read_csv()
# 讀取excel數(shù)據(jù)
#pd.read_excel()
# 讀取txt數(shù)據(jù)
#pd.read_table()
結(jié)果如圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多
總結(jié)
以上是生活随笔為你收集整理的python读取mysql数据_如何将mysql的数据读取python的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ctypes python_Python
- 下一篇: mysql存储文件用什么类型_块存储、文