【发布时间】:2018-07-19 06:29:46
【问题描述】:
我打算使用 SQLAlchemy 将 pandas 数据框导出到 MySQL。尽管参考了所有以前的帖子,但我无法解决问题:
import pandas as pd
import pymysql
from sqlalchemy import create_engine
df=pd.read_excel(r"C:\Users\mazin\1-601.xlsx")
cnx = create_engine('mysql+pymysql://[root]:[aUtO1115]@[localhost]:[3306]/[patenting in psis]', echo=False)
df.to_sql(name='inventor_dataset', con=cnx, if_exists = 'replace', index=False)
以下是错误:
OperationalError: (pymysql.err.OperationalError) (2003, "无法连接 到 'localhost] 上的 MySQL 服务器:[3306' ([Errno 11001] getaddrinfo 失败)”)
【问题讨论】:
-
可以通过cmd/terminal连接sql数据库吗?
-
@iam.Carrot - 我第一次使用 Python 与 MySQL 交互。我能够从 Python 中的示例 MySQL 表中输入数据作为 pandas 数据框。
标签: python mysql python-3.x sqlalchemy mysql-python