我正在尝试将 MySQLdb 连接到 MySQL。当我的服务器是 localhost 和端口 80 时,它工作正常。但由于某种原因,我不得不将端口更改为 8080。现在如何在连接命令中指定端口?
这是我之前使用的:
db = MySQLdb.connect(host = "localhost", user = "root", passwd = "", db = "pymysql")
现在我的服务器是“localhost:8080”。那么我应该在哪里提供有关此端口的信息?我试过这个:
db = MySQLdb.connect(host = "127.0.0.1:8080", user = "root", passwd = "", db = "pymysql")
这就是我得到的:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
db = MySQLdb.connect(host = "127.0.0.1:8080", user = "root", passwd = "", db = "pymysql")
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: (2005, "Unknown MySQL server host '127.0.0.1:8080' (11004)")
请帮忙 !!!