【发布时间】:2016-07-02 23:21:37
【问题描述】:
我使用的是 Mac (OS 10.10.5)、PyCharm、Python 3.5 和 MySQL。 MySQL 一直在同一台机器上使用 PHP。我正在尝试使用 Python 连接到它并收到错误消息:
enter code here2003:无法连接到 'localhost::3306' 上的 MySQL 服务器(提供了 8 个节点名或服务名,或未知)
有人可以列出诊断步骤以便我解决问题吗?谢谢,道格
下面是连接代码: 导入 mysql.connector 从 mysql.connector 导入错误码
try:
cnn = mysql.connector.connect(
host="localhost:", # your host, usually localhost
user="root", # your username
password="root", # your password
database="bb_cards") # name of the data base
print("It Works!!")
except mysql.connector.Error as e:
if e.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with username or Password")
elif e.errno == errorcode.ER_BAD_DB_ERROR:
print("Database Does not exist")
else:
print(e)
【问题讨论】: