[英]Connect MySql to a machine on the same network
我正在尝试将机器脚本X连接到机器Y上的数据库。 我可以在机器Y上完美地处理银行,但是当我运行机器X时,出现以下错误:
"2003 (HY000): Can't connect to MySQL server on '172.22.128.1:3306 (10060)"
下面我的连接脚本插入到机器Y
declaracao = f'INSERT INTO similares (momento,produto1,produto2,res) VALUES ("teste","teste","teste",10.00);'
try:
#CREATE CONNECTION MYSQL
con = mysql.connector.connect(user='root', password='root', host='172.22.128.1', database='saneamento') #Here where to return the error
cursor = con.cursor()
cursor.execute(declaracao)
con.commit()
print(cursor.rowcount, "Insert dados!")
cursor.close()
except Error as e:
print("Fail", e)
电脑下方IP X
Adress IPv4. . . . . . . . . . . . . . . : 172.22.128.1
计算机 X 和 Y 在同一网络上
您可以从远程服务器手动连接到您的 mysql 数据库吗?
远程 linux 服务器> mysql -D <数据库> -h <主机> -u <用户> -p -e "<mysql 命令>"
如果失败,您应该检查 mysql 是否允许 root 用户从远程主机连接。 您可能使用 root@localhost 条目而不是 root@<remote host> 条目来设置它。
mysql> select * 来自 mysql.user;
如果你只有一个 root 的 localhost 条目,你可以在 Linux 上添加一个远程主机条目。
mysql> CREATE USER 'root'@'remote_server_ip' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON <database_name>.* TO 'root'@'remote_server_ip' WITH GRANT OPTION;
mysql> 刷新权限;
** 请注意,您可以将 'remote_server_ip' 替换为 '%' 以允许从任何远程服务器进行访问。
如果它仍然不起作用,您可能需要检查您的防火墙。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.