1

I want to interact with some data from an SQL database in Python, but am having connection issues. I've verified that the information below is correct, as I'm able to use these credentials (stored in a YAML file) to log in to the database via MySQL Workbench 6.3 CE.

user_db : *******
user_host : **********
user_port : 3306
user_username: username
user_password: password

Here is the connection code within my 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'])

Regardless of whether or not I try to connect using the YAML file or just use the values within it, I get this error in my Ipython Notebook. The line indicated is the 'port' line above.

OperationalError: could not send data to server: Software caused connection
abort (0x00002745/10053)
could not send startup packet: Software caused connection abort
(0x00002745/10053)

I'm able to use identical code to log in to a Redshift database using port 5439, but I'm wondering what is causing this particular error.

scoloe
  • 215
  • 1
  • 2
  • 8
  • It might be related to SSL settings of the connection. Are you using it? If yes, a non-ssl connection is likely dropped outright. Try adding `sslmode=require` to the connection parameters. – 9000 Jun 07 '16 at 21:32
  • 1
    you tagged the question as mysql but psycopg is a PostgreSQL adapter. – limbo Jun 07 '16 at 21:41
  • 1
    I believe the adapter is the problem. I would recommend using pymysq for a MySQL database. – limbo Jun 07 '16 at 21:52

1 Answers1

3

It seems like you're trying to connect to MySQL (port 3306) using a PostgreSQL client library (psycopg2), which also works for Redshift because Redshift is based on Postgres.

Please try installing PyMySQL or any of the alternatives.

Community
  • 1
  • 1
hdiogenes
  • 729
  • 7
  • 15