
我可以本地連接,但不能遠端連接。
在我的客戶上我有:
mysql Ver 8.0.35-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))
在我的伺服器上我有:
mysql Ver 8.2.0 for Linux on x86_64 (MySQL Community Server - GPL)
我嘗試像這樣連接:
mysql -h 10.0.1.242 -P 33060 -u bob -p
我得到(輸入密碼後螢幕掛起相當長一段時間):
ubuntu@ubuntu-webserver-instance:~$ mysql -h 10.0.1.242 -P 33060 -u bob -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '10.0.1.242:33060' (110)
我的用戶有:
CREATE DATABASE pets;
CREATE USER 'bob'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON pets.* TO 'bob'@'%';
FLUSH PRIVILEGES;
我已經編輯/etc/mysql/my.cnf
嘗試:
[mysqld]
bind_address = 0.0.0.0
Jan 17 01:02:20 ubuntu-database-instance mysqld[4672]: 2024-01-17T01:02:20.265066Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/>
[mysqld]
bind_address = 0.0.0.0
mysqlx_bind_address = 0.0.0.0
Jan 17 01:16:37 ubuntu-database-instance mysqld[4783]: 2024-01-17T01:16:37.880551Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '0.0.0.0' port: 33060, socket: /var/run/my>
我有點難住了。
答案1
知道了!
iptables -I INPUT 6 -m state --state NEW -p tcp --dport 3306 -j ACCEPT
答案2
嘗試本機連線:在同一個Mysql SQL Server上,使用:mysql -h localhost -P 33060 -u bob -p
如果可以連接,則檢查伺服器和用戶端兩端的防火牆