zoukankan      html  css  js  c++  java
  • 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')
  • 相关阅读:
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Oil Skimming HDU
    Rain on your Parade HDU
    Swap HDU
    棋盘游戏 HDU
  • 原文地址:https://www.cnblogs.com/shenxiaolin/p/8205316.html
Copyright © 2011-2022 走看看