Shawn31313
Shawn31313

Reputation: 6052

"Can't connect to MySQL server on 'localhost' (10061)" error in python

Just today I have decided that I wanted to learn python because I personally like the syntax and its feel. I am a pretty young developer and I really wanted to learn a new programming language since I am only fluent in JavaScript (especially javascript) and PHP so I decided on Python. Python seems quite like javascript execpt for the fact that they don't use curly braces to define a new block. And of course its far more powerful.

I've learned that you can connect to MySQL databases using MySQLdb .

But I am having an issue, when I use the following code.

db = MySQLdb.connect(host="localhost", user="methodjs_postes", passwd="********", db="methodjs_postes");

I get this large error:

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    db = MySQLdb.connect(host="localhost", user="methodjs_postes", passwd="********", db="methodjs_postes");
  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)")

The main part that I was really focusing on though was the Can't connect to MySQL server on 'localhost' (10061) part. (But it would be nice if you explain the other parts too)

I don't see why i'm getting this issue. I use localhost in my PHP and it works just fine. And I did import the MySQLdb which I don't think is the error because then it wouldn't even attempt to connect.

I am using python 2.7, I would be using 3.3 (have it downloaded) but MySQLdb only supports up to 2.7.

When using select User,Host,Password from mysql.user where User like '%methodjs_postes%'; I get the following error:

SELECT command denied to user 'methodjs'@'localhost' for table 'user'

Upvotes: 1

Views: 13059

Answers (2)

Anubhav
Anubhav

Reputation: 933

Just replace localhost with 127.0.0.1

Upvotes: 3

Suku
Suku

Reputation: 3880

https://chat.stackoverflow.com/rooms/22618/discussion-between-shawn31313-and-suku

As per out chat, the conclusion is :- "Your mysql host is a remote machine and which is not allowing remote mysql connections"

Upvotes: 0

Related Questions