MySQLdb connection problems

后端 未结 7 1027
逝去的感伤
逝去的感伤 2020-12-30 05:37

I\'m having trouble with the MySQLdb module.

db = MySQLdb.connect(
    host = \'localhost\', 
    user = \'root\', 
    passwd = \'\', 
    db = \'testdb\',          


        
相关标签:
7条回答
  • 2020-12-30 06:28

    Make sure that the mysql server is listening for tcp connections, which you can do with netstat -nlp (in *nix). This is the type of connection you are attempting to make, and db's normally don't listen on the network by default for security reasons. Also, try specifying --host=localhost when using the mysql command, this also try to connect via unix sockets unless you specify otherwise. If mysql is not configured to listen for tcp connections, the command will also fail.

    Here's a relevant section from the mysql 5.1 manual on unix sockets and troubleshooting connections. Note that the error described (2002) is the same one that you are getting.

    Alternatively, check to see if the module you are using has an option to connect via unix sockets (as David Suggests).

    0 讨论(0)
提交回复
热议问题