無法透過 ssh 隧道連接到 AWS 上的 mysql

無法透過 ssh 隧道連接到 AWS 上的 mysql

我正在嘗試打破任務將 ruby​​mine 分成更小的區塊進行 AWS 偵錯。我想連接到在 AWS 上運行的 mysql 伺服器。所以我做了以下事情:

第一的:建立 ssh 隧道,將所有對連接埠 3307 的 localhost 請求轉送到 AWS 上的連接埠 3306:

ssh -l ubuntu -i 'path/to/private/key/privateKey.cer' -L 3307:aws.port:3306 aws.port -N -v -v

第二:連接mysql的3307端口

mysql -h 127.0.0.1 -P 3307 -u root -p 

問題: 它在我的主機上失敗並出現以下錯誤:

ERROR 1130 (HY000): Host '178.135.138.61' is not allowed to connect to this MySQL server

AWS 上的日誌輸出如下:

debug1: Connection to port 3307 forwarding to 54.193.1.19 port 3306 requested.
debug2: fd 7 setting TCP_NODELAY
debug1: channel 2: new [direct-tcpip]
channel 2: open failed: connect failed: Connection refused
debug2: channel 2: zombie
debug2: channel 2: garbage collecting
debug1: channel 2: free: direct-tcpip: listening port 3307 for 54.193.1.19 port 3306, connect from 127.0.0.1 port 64938, nchannels 3

筆記:

  • 我確保我連接的 aws 伺服器的安全群組允許ssh連接埠 22 上的連接
  • 我確保/etc/hosts.denyAWS 上沒有列出 localhost 或 127.0.0.1。

想法?

答案1

錯誤訊息

ERROR 1130 (HY000): Host '178.135.138.61' is not allowed to connect to this MySQL server

來自MySQL。要允許 root 使用者遠端訪問,您需要在 mysql 伺服器上專門允許特定資料庫進行此操作

mysql -u root -p
mysql> grant all privileges on somedatabase.* to 'root'@'178.135.138.61' identified by 'somepassword';
mysql> flush privileges;

這將允許使用者名稱 root 從 178.135.138.61 連接到 mysql,並擁有某個資料庫的所有權限。

您可能應該通讀MySQL 安全性文檔特別是存取控制使用者管理章節。

相關內容