Search code examples
pythonmysqlpymysql

Pymysql can not link to the mysql


enter image description here

here is mysql

ps:I work in win7 virtualbox system,and I blocked the virtual network card,is that reason it?


Solution

  • You're using a Unix socket (hence the AF_UNIX in the error) to connect to MySQL, where it's not available on the platform (Windows). I suggest using a TCP connection instead.

    Remove the unix_socket argument to pymysql.connect call, and replace it with port=3306. So the connection line will be like this:

    conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='something', db='mysql')
    

    Also make sure MySQL server accepts network connections as well. This can be set on MySQL server configurations. If MySQL server is running on the same host where you're writing the client, then it should be fine. Otherwise you might need to allow connection from clients on other hosts to MySQL server.