lundi 27 juin 2016

Connecting to mysql via Python script


I had installed mysql connector/python and was using MAMP. I somehow ended up changing my root password,but that caused problems in opening phpmyadmin, so i changed it back to root which was the default password. It seemed to be working fine but when I tried to connect to a database,this is what came up in the terminal :

Traceback (most recent call last):
File "database.py", line 7, in <module>
    raise_on_warnings= True)
File "/Library/Python/2.7/site-packages/mysql/connector/__init__.py", line 179, in connect
        return MySQLConnection(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/mysql/connector/connection.py", line 95, in __init__
    self.connect(**kwargs)
  File "/Library/Python/2.7/site-packages/mysql/connector/abstracts.py", line 719, in connect
    self._open_connection()
  File "/Library/Python/2.7/site-packages/mysql/connector/connection.py", line 206, in _open_connection
    self._socket.open_connection()
  File "/Library/Python/2.7/site-packages/mysql/connector/network.py", line 475, in open_connection
    errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:8889:3306' (60 Operation timed out)

So i tried but nothing worked. I ended up uninstalling MAMP. And then I ran the script again. However,it still gives the same error! I couldn't uninstall connector/python.
Here's the python script if required:

import mysql.connector

con = mysql.connector.connect(user='root',
                              password ='root',
                              host='localhost:8889',
                              database='testdb',
                              raise_on_warnings= True)

cur = con.cursor()

cur.close()
con.close()

What could be the problem?


Aucun commentaire:

Enregistrer un commentaire