将MySql连接到同一网络上的计算机



我正在尝试将机器脚本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)

低于计算机IPX

Adress IPv4. . . . . . . .  . . . . . . . : 172.22.128.1

设置XAMPP:

设置MySQL

设置phpMyAdmin

计算机X和Y在同一网络上

您可以从远程服务器手动连接到MySQL数据库吗?

remote linux server> mysql -D <database> -h <host> -u <user> -p -e "<mysql command>"

如果失败,您应该检查MySQL是否允许root用户从远程主机连接。您可以使用root@localhost条目,但不是根@<远程主机>进入

mysql> select * from 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> FLUSH PRIVILEGES;

**请注意,您可以将"remote_server_ip"替换为"%",以允许从任何远程服务器进行访问。

如果它仍然不起作用,你可能需要检查你的防火墙。

最新更新