我想与Python中的SQL数据库中的某些数据进行交互,但是我遇到了连接问题。我已经验证了以下信息是正确的,因为我可以使用这些凭据(存储在YAML文件中)通过MySQL Workbench 6.3 CE登录数据库。
user_db : *******
user_host : **********
user_port : 3306
user_username: username
user_password: password
这是我的Ipython Notebook中的连接代码:
prod_db = psycopg2.connect(database=credentials['user_db'],
user=credentials['user_username'],
password=credentials['user_password'],
host=credentials['user_host'],
port=credentials['user_port'])
无论我是否尝试使用YAML文件进行连接或仅使用其中的值,我都会在Ipython Notebook中收到此错误。指示的线是上面的“端口”线。
OperationalError: could not send data to server: Software caused connection
abort (0x00002745/10053)
could not send startup packet: Software caused connection abort
(0x00002745/10053)
我可以使用相同的代码使用端口5439登录Redshift数据库,但我想知道导致此特定错误的原因。
答案 0 :(得分:2)
您似乎正在尝试使用PostgreSQL客户端库(psycopg2)连接到MySQL(端口3306),这也适用于Redshift,因为Redshift基于Postgres。
请尝试安装PyMySQL或任何alternatives。