This article mainly for you in detail how Python read MySQL database table data, with a certain reference value, interested in small partners can refer to
The example of this article for everyone to share the Python read MySQL database table data specific code for your reference, the specific content is as follows
Environment: Python 3.6, Window 64bit
Objective: To read the target table data from the MySQL database and to process
Code:
#-*-Coding:utf-8-*-Import pandas as Pdimport Pymysql # # plus character set parameters to prevent Chinese garbled dbconn=pymysql.connect ( host= "**********", database= "Kimbo", user= "Kimbo_test", password= "******", port=3306, charset= ' UTF8 ') # SQL statement sqlcmd= "Select Col_name,col_type,col_desc from Itf_datadic_dtl_d limit" #利用pandas module to import MySQL data a=pd.read_sql ( Sqlcmd,dbconn) #取前5行数据b =a.head () print (b) # read CSV data # pd.read_csv () # Read the Excel Data #pd.read_excel () # Read TXT data #pd.read_ Table ()
Results
"Recommended"
1. Python Free video tutorial
2. Python Learning Manual
3. Python Object-oriented video tutorial