2

我知道该错误已在网上某处讨论过,但是我的在这里有点不同:

我有一个要在 PyCharm 中完成的脚本(我喜欢在那里使用调试功能),该脚本具有以下代码来连接到本地 mysql 数据库:

try:
    # create connection to mysql
    connection = mysql.connector.connect(host='localhost',
                                         database='<the db>',
                                         user='<the user>',
                                         password='<the password>')

except mysql.connector.Error as error:
    print("Error: {}".format(error))

finally:
    print("MySQL connection cannot be established")

我在 PyCharm 中收到以下错误:

2003: Can't connect to MySQL server on 'localhost:3306' (10060 连接尝试失败,因为连接方一段时间后没有正确响应,或者建立连接失败,因为连接的主机没有响应)

但是我在 mysql 控制台中没有收到错误。

我该如何解决这个问题?

非常感谢。

4

1 回答 1

1

I found the fix to my issue:

mysql> grant all on *.* to '<the user>@localhost' identified by '<the password>' with gran
t option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)
于 2020-02-21T15:44:28.667 回答