Python 3.x 连接 pymysql 数据库
首先,需要安装库:
使用 pycharm IDE,如PyCharm,可以使用 project python 安装第三方模块。
[File] >> [settings] >> [Project: python] >> [Project Interpreter] >> [Install按钮]


Python语句连接数据库并提取数据:
import pymysql import pandas as pd con = pymysql.connect(host='4', port=3, user='g', passwd='G1', db='gr', charset='GBK') cur = con.cursor() cur.execute("sa.tables where table_schema='g';") tableList = cur.fetchall() for tableName in tableList: print(tableName[0]) df = pd.read_sql('SELECT * FROM ' + tableName[0], con) df.to_csv(tableName[0] + '.csv')
posted on 2018-01-05 16:24 CuriousZero 阅读(178) 评论(0) 收藏 举报
 
                    
                     
                    
                 
                    
                 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号