连接远程mySQL服务器失败,我确保MySQL正在运行,Django可以成功连接,但希望连接python与mySQL失败
- python代码(在谷歌colab中运行)
import mysql.connector
mydb = mysql.connector.connect(
host="196.xxx.xxx.xxx",
user="xxxxx",
passwd="xxxxxx",
database="Unnamed" # I tried to put "cloud_db" and "Unnamed" is not work
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM webpage")
myresult = mycursor.fetchall()
for row in myresult:
print(row)
- 误差输出
---------------------------------------------------------------------------
MySQLInterfaceError Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/mysql/connector/connection_cext.py in _open_connection(self)
267 try:
--> 268 self._cmysql.connect(**cnx_kwargs)
269 self._cmysql.converter_str_fallback = self._converter_str_fallback
MySQLInterfaceError: Can't connect to MySQL server on '196.xxx.xxx.xxx:3306' (113)
The above exception was the direct cause of the following exception:
DatabaseError Traceback (most recent call last)
4 frames
/usr/local/lib/python3.8/dist-packages/mysql/connector/connection_cext.py in _open_connection(self)
271 self.converter.str_fallback = self._converter_str_fallback
272 except MySQLInterfaceError as err:
--> 273 raise get_mysql_exception(
274 msg=err.msg, errno=err.errno, sqlstate=err.sqlstate
275 ) from err
DatabaseError: 2003 (HY000): Can't connect to MySQL server on '196.xxx.xxx.xxx:3306' (113)
当我连接Django和mySQL时,下面的信息可以正常工作,但是python到MySQL的连接仍然有效
1条答案
按热度按时间q3qa4bjr1#
我建议您先使用SQL工具连接,如果连接成功,您就可以知道
host
、password
..是否正确,然后是编码问题