我正在尝试使用下面的代码连接到MYSQL数据库服务器。
import mysql.connector
from mysql.connector
import connection
conn = connection.MySQLConnection(
host='*****', username='****', password='*****',
database='****', port=3306)
但它引发了以下错误:
PS C:\Users\InfoASB-McMConstruct\OneDrive - ASB-McM UK Construction\Desktop\Anjali\Scripts> & 'C:\Users\InfoASB-McMConstruct\AppData\Local\Programs\Python\Python311\python.exe' 'c:\Users\InfoASB-McMConstruct\.vscode\extensions\ms-python.python-2023.6.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '53639' '--' 'C:\Users\InfoASB-McMConstruct\OneDrive - ASB-McM UK Construction\Desktop\Anjali\Scripts\fetchData.py'
Traceback (most recent call last):
File "C:\Users\InfoASB-McMConstruct\AppData\Local\Programs\Python\Python311\Lib\site-packages\mysql\connector\connection_cext.py", line 291, in _open_connection
self._cmysql.connect(**cnx_kwargs)
_mysql_connector.MySQLInterfaceError: Unknown MySQL server host 'db5012717913.hosting-data.io' (11001)
上述异常是以下异常的直接原因:
Traceback (most recent call last):
File "C:\Users\InfoASB-McMConstruct\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\InfoASB-McMConstruct\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 88, in _run_code
exec(code, run_globals)
File "c:\Users\InfoASB-McMConstruct\.vscode\extensions\ms-python.python-2023.6.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
cli.main()
File "c:\Users\InfoASB-McMConstruct\.vscode\extensions\ms-python.python-2023.6.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\InfoASB-McMConstruct\.vscode\extensions\ms-python.python-2023.6.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\Users\InfoASB-McMConstruct\.vscode\extensions\ms-python.python-2023.6.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\InfoASB-McMConstruct\.vscode\extensions\ms-python.python-2023.6.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "c:\Users\InfoASB-McMConstruct\.vscode\extensions\ms-python.python-2023.6.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "C:\Users\InfoASB-McMConstruct\OneDrive - ASB-McM UK Construction\Desktop\Anjali\Scripts\fetchData.py", line 9, in <module>
conn = mysql.connector.connect(host='db5012717913.hosting-data.io',
self.connect(**kwargs)
File "C:\Users\InfoASB-McMConstruct\AppData\Local\Programs\Python\Python311\Lib\site-packages\mysql\connector\abstracts.py", line 1181, in connectb\site-packages\mysql\connector\abstracts.py", line 1181, in connect
self._open_connection() b\site-packages\mysql\connector\connection_cext.py", line 296, in _open_connection
File "C:\Users\InfoASB-McMConstruct\AppData\Local\Programs\Python\Python311\Lion
raise get_mysql_exception(
mysql.connector.errors.DatabaseError: 2005 (HY000): Unknown MySQL server host 'db5012717913.hosting-data.io' (11001)
有人能帮我解析stacktrace,并协助找到解决问题的方法吗?
1条答案
按热度按时间ru9i0ody1#
你的问题的标题意味着你的python代码想要使用一个MySQL服务器,它位于DNS名称为
db5012717913.hosting-data.io
的主机上。但是这个主机名不在DNS中。获取MySQL服务器的正确主机名,并将其放入连接构造函数的
host
参数中。