-1

I know that I need to "import MySQLdb" to connect to a MySQL database. But what is the name of the library that we need to import when we are using "cleardb mysql"?

I am hard coding as below to connect, but I guess due to wrong library, I am getting errors. Below are my points to explain my situation::

1) I have installed "MySQldb", and imported it through import keyword.

2) when I use port number in the connectivity syntax, I got "TypeError: an integer is required".

db = MySQLdb.connect("server_IP",3306,"uid","pwd","db_name")

so I removed the port number

import MySQLdb
db = MySQLdb.connect("server_IP","uid","pwd","db_name")
cur = db.cursor()

and the error vanishes. Is that the right method?

3) Everything goes fine until I execute the function "curson.execution("SELECT VERSION()")" to execute sql queries.

curson.execution("SELECT VERSION()")

I am getting error as below

Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    cursor.execute("use d_7fc249f763d6fc2")
  File "path_to\cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "path_to\connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (2006, 'MySQL server has gone away')

So, is this happening due to library that I have imported? or, if the library is correct, then what seems to be the issue?

user3521180
  • 1,044
  • 2
  • 20
  • 45

1 Answers1

1

The port number is the fifth positional argument, not the second.

db = MySQLdb.connect("server_IP", "uid", "pwd", "db_name", 3306)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • ,okay, got that, and I can see the changes in the error now that I get, its complaining about the host name, that I will take care off. So, can I assume that, the library "MySQLdb" is rightly imported , and applicable even in the case of " "cleardb mysql"? – user3521180 May 04 '17 at 13:39
  • I'm sorry I have no idea what you mean here. ClearDB appear to be a provider of MySQL in the cloud. How does this relate to your question? – Daniel Roseman May 04 '17 at 13:44
  • In my environment, it's not just Mysql, its cleardb MySQL, and since I have also seen that for the first time, so I was wondering if the code is rightly placed to achieve our goal including the library. As, to connect to MySQL database, we need "MySQLdb" library, so I was wondering if we can use same library even in case of this cleardb? Hope I am clear with my query now.. – user3521180 May 04 '17 at 13:47