2

I want to transfer my data from json into mysql for that I install the python library MySQLdb . It import successfully but it gives error while connecting

>>> import MySQLdb
>>> db=MySQLdb.connect(passwd="king123",db="thangs")

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    db=MySQLdb.connect(passwd="king123",db="thangs")
  File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")

>>> import _mysql
>>> db=_mysql.connect()

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    db=_mysql.connect()
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")

db=MySQLdb.connect(passwd="rat123",db="thangs",host="localhost",port=1028,user="mroot")

Traceback (most recent call last):
  File "<pyshell#41>", line 1, in <module>
db=MySQLdb.connect(passwd="king123",db="thangs",host="localhost",port=1028,user="munieb")


File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2013, "Lost connection to MySQL server at 'waiting for initial communication packet', system error: 2")
2
  • 2
    Is your mysql database running on the same computer on port 10061? Commented Nov 15, 2012 at 18:49
  • no, but mysql php admin is also installed Commented Nov 15, 2012 at 18:50

2 Answers 2

1

You need to specify the server and point.

db=MySQLdb.connect(passwd="king123",db="thangs",host="hostname",port=3251,user="user")
Sign up to request clarification or add additional context in comments.

3 Comments

OperationalError: (2005, "Unknown MySQL server host 'hostname' (0)") it give the following error
Well, you have to change it to match the server you want to use... Get the information of your database. I can't tell you what that is...
how I get my database info ?
1

I had the same problem and for me, the problem was with ip address which mysql listened to port 3305 on. By netstat -aon I saw:

Proto  Local Address          Foreign Address        State           PID
...
TCP    0.0.0.0:3306            0.0.0.0:0              LISTENING       884
...

So I uncommented line below in my.ini config file:

#bind-address="127.0.0.1" 

then restarted mysql and problem gone!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.