Created
May 14, 2018 17:19
-
-
Save dei-biz/78fd11b0355dd3e43942242892760aa3 to your computer and use it in GitHub Desktop.
Python3 XLSX from MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| host = 'HOST' | |
| port = 3306 | |
| user = 'USER' | |
| password = 'PASS' | |
| database = 'DATABASE' | |
| writer = pd.ExcelWriter(database+'.xlsx') | |
| conn = pymysql.connect( | |
| host=host, | |
| port=int(port), | |
| user=user, | |
| passwd=password, | |
| db=database, | |
| charset='latin1') | |
| tables = pd.read_sql_query("SELECT TABLE_NAME AS t FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '"+database+"'", | |
| conn) | |
| for index, row in tables.iterrows(): | |
| df = pd.read_sql_query("SELECT * from "+row.t, conn) | |
| df.to_excel(writer, row.t) | |
| writer.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment