Connecting to MySQL over network

Asked by Kurian

Hi,

I am just 1 day old with python. I use Bash for doing most of the scripting. Thought of giving python a try. I installed mysql.connector module and I used the code posted in http://geert.vanderkelen.org/2009/09/how-to-install-mysql-connectorpython.html for MySQL connection just for the start. The following the code.

#!/usr/bin/python
import mysql.connector

if __name__ == "__main__":
    db = mysql.connector.Connect(host="192.168.0.2",user="kurianmt",password="reiper",database="test",port="3307")
    cursor = db.cursor()
    cursor.execute("SHOW ENGINES")

    for row in cursor.fetchall():
       print row

    cursor.close()
    db.close()

When I run the script, its giving me error.

$ ./3.py
Traceback (most recent call last):
  File "./3.py", line 5, in <module>
    db = mysql.connector.Connect(host="192.168.0.2",user="kurianmt",password="reiper",database="test",port="3307")
  File "/usr/lib/python2.6/site-packages/mysql/connector/__init__.py", line 45, in Connect
    return MySQL(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/mysql/connector/mysql.py", line 324, in __init__
    self.connect(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/mysql/connector/mysql.py", line 425, in connect
    self._open_connection()
  File "/usr/lib/python2.6/site-packages/mysql/connector/mysql.py", line 98, in _open_connection
    self.conn.open_connection()
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 167, in open_connection
    raise errors.InterfaceError('%s' % e)
mysql.connector.errors.InterfaceError: -1: an integer is required

I am sure that I am missing something here. Would appreciate if you can point me out what I am doing wrong here. Thanks in advance.

Regards,

Kurian Thayil.

Question information

Language:
English Edit question
Status:
Solved
For:
MySQL Connector/Python Edit question
Assignee:
Geert JM Vanderkelen Edit question
Solved by:
Geert JM Vanderkelen
Solved:
Last query:
Last reply:
Revision history for this message
Best Geert JM Vanderkelen (geertjmvdk) said :
#1

port="3306" must be port=3306 (it must be an integer)

We've created a bug report to make the error clearer or handle it better.

Revision history for this message
Geert JM Vanderkelen (geertjmvdk) said :
#2

Changing the port argument to an integer should work.
 mysql.connector.connect(port=3306)

Revision history for this message
Kurian (kurianthayil) said :
#3

Thanks Geert JM Vanderkelen, that solved my question.

Revision history for this message
Kurian (kurianthayil) said :
#4

Thanks Geert.. It fixed the problem..