我无法连接到我的 testdb 数据库以便在数据库中创建表(如下面的脚本图 1 所示)。使用相同的连接参数,我之前能够连接到 Azure MySQL 服务器以从 VM 终端创建 testdb 服务器,但现在我无法连接到数据库以创建表。
生成了错误消息(如图 2 所示),如下所示。请注意,数据库服务器连接设置为允许来自公共和 Microsoft Azure 资源的流量,但我的脚本无法成功执行。
命令与结果
azproj2@GL-AZ-PROJ2-VM:~/home/ubuntu$ python3 process.py
*********************** Processing File *****************************
File has been processed
Uploading to Azure Storage as blob: docproc.csv
inv-00001
Mar 31 2018
*************************************************************************
Creating table invoice
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/mysql/connector/network.py", line 703, in open_connection
addrinfos = socket.getaddrinfo(
File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "process.py", line 54, in <module>
main()
File "process.py", line 42, in main
conn = mysql.connector.connect(host=hostname, user=username, passwd=password, db=database)
File "/usr/local/lib/python3.8/dist-packages/mysql/connector/pooling.py", line 294, in connect
return MySQLConnection(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/mysql/connector/connection.py", line 169, in __init__
self.connect(**kwargs)
File "/usr/local/lib/python3.8/dist-packages/mysql/connector/abstracts.py", line 1217, in connect
self._open_connection()
File "/usr/local/lib/python3.8/dist-packages/mysql/connector/connection.py", line 575, in _open_connection
self._socket.open_connection()
File "/usr/local/lib/python3.8/dist-packages/mysql/connector/network.py", line 723, in open_connection
raise InterfaceError(
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '%-.100s:%u' (%s) (Warning: %u format: a number is required, not str)
谁有可行的解决方案?