Windows 10 上の DataGrip をクライアントとして使用し、SSH トンネルを介してリモート MySQL サーバーに接続しようとすると、「SSH トンネルの作成に失敗しました: 開くことができませんでした」というメッセージが表示されます。
次のようにして、トンネルを正常に確立して接続できますssh username@mysqlServer -L 22:remoteHost:3306
。
私は、接続をテストするときにデバッグ情報を提供するため、問題の主なデモンストレーションとして datagrip を使用していますが、dbeaver と tableplus でも試しましたが、どちらも接続に失敗しました。
私の組織内の他のユーザーは、macOS マシン上でリモート MySQL サーバーに問題なく接続できます。
DataGrip からのログ:
2022-04-18 14:58:14,313 [ 57564] INFO - n.s.s.t.r.JCERandom - Creating new SecureRandom.
2022-04-18 14:58:14,411 [ 57662] INFO - #c.i.s.i.s.sshj - Client identity string: SSH-2.0-IntelliJ__DataGrip_DB-221.5080.224__SSHJ_0.32.0_idea2
2022-04-18 14:58:14,508 [ 57759] INFO - #c.i.s.i.s.sshj - Server identity string: SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.8
2022-04-18 14:58:15,258 [ 58509] INFO - #c.i.s.i.s.sshj - Authentication log: SSH connection to username@mysqlServer:22
* With altered connection settings:
- authMethods: PublicKey(privateKeys=[C:\Users\spenc\.ssh\id_rsa, C:\Users\spenc\.ssh\id_dsa, C:\Users\spenc\.ssh\id_ecdsa, C:\Users\spenc\.ssh\id_ed25519, C:\Users\spenc\.ssh\id_xmss], agent=NO), Password, KeyboardInteractive
- user: username
* Connected: Socket[addr=mysqlServer/mysqlServer,port=22,localport=63766]
* Starting authentication
=> none (failure, new auth methods allowed by the server: publickey)
=> publickey C:\Users\spenc\.ssh\id_rsa (success)
2022-04-18 14:58:15,270 [ 58521] INFO - #c.i.d.d.DatabaseSshTunnelEstablisher - SSH tunnel created: 63768:remoteHost:3306
2022-04-18 14:58:15,317 [ 58568] INFO - #c.i.e.r.RemoteProcessSupport - "C:\Program Files\JetBrains\DataGrip 2022.1.1\jbr\bin\java" -Djava.rmi.server.hostname=127.0.0.1 -Duser.timezone=UTC -Xmx750m -Xms128m -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\DataGrip 2022.1.1\lib\util_rt.jar;C:\Program Files\JetBrains\DataGrip 2022.1.1\lib\util.jar;C:\Program Files\JetBrains\DataGrip 2022.1.1\lib\groovy.jar;C:\Program Files\JetBrains\DataGrip 2022.1.1\plugins\DatabaseTools\lib\jdbc-console.jar;C:\Users\spenc\AppData\Roaming\JetBrains\DataGrip2022.1\jdbc-drivers\MySQL ConnectorJ\8.0.25\mysql-connector-java-8.0.25.jar" com.intellij.database.remote.RemoteJdbcServer com.mysql.cj.jdbc.Driver
2022-04-18 14:58:15,705 [ 58956] INFO - #c.i.e.r.RemoteProcessSupport - Port/ServicesPort/ID: 58696/63770/RemoteDriverImpld6de775c
2022-04-18 14:58:15,713 [ 58964] INFO - #c.i.e.r.RemoteProcessSupport -
2022-04-18 14:58:15,772 [ 59023] INFO - #c.i.d.d.DatabaseConnectionEstablisher - Connecting to: jdbc:mysql://remoteHost:3306/dbName
2022-04-18 14:58:15,774 [ 59025] INFO - #c.i.d.d.DatabaseConnectionEstablisher - Auth provider: user-pass
2022-04-18 14:58:15,776 [ 59027] INFO - #c.i.d.d.DatabaseCredentialsAuthProvider - Connecting as: username
2022-04-18 14:58:15,778 [ 59029] INFO - #c.i.d.d.DatabaseConnectionEstablisher - Connecting to (rewritten): jdbc:mysql://localhost:63768/dbName
2022-04-18 14:58:15,987 [ 59238] WARN - #c.i.s.i.s.sshj - <<chan#0 / open>> woke to: Opening `direct-tcpip` channel failed: open failed
2022-04-18 14:58:15,989 [ 59240] INFO - #c.i.s.i.s.sshj - Error in `SSHJ local tunnel for SshjSshConnection(username@mysqlServer)@82260ee: Local client /127.0.0.1:63774 ==> Local server localhost:63768 ==> Remote server remoteHost:3306`: net.schmizz.sshj.connection.channel.OpenFailException: open failed
2022-04-18 14:58:16,016 [ 59267] WARN - #c.i.d.d.BaseDatabaseErrorHandler$IOErrorInfo - Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.cj.protocol.FullReadInputStream.readFully(FullReadInputStream.java:67)
at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:63)
at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:45)
at com.mysql.cj.protocol.a.NativeProtocol.readMessage(NativeProtocol.java:540)
at com.mysql.cj.protocol.a.NativeProtocol.readServerCapabilities(NativeProtocol.java:498)
at com.mysql.cj.protocol.a.NativeProtocol.beforeHandshake(NativeProtocol.java:385)
at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1351)
at com.mysql.cj.NativeSession.connect(NativeSession.java:157)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:953)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at com.intellij.database.remote.jdbc.helpers.JdbcHelperImpl.connect(JdbcHelperImpl.java:639)
at com.intellij.database.remote.jdbc.helpers.MysqlBaseJdbcHelper.connect(MysqlBaseJdbcHelper.java:244)
at com.intellij.database.remote.jdbc.impl.RemoteDriverImpl.connect(RemoteDriverImpl.java:55)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Suppressed: com.intellij.database.util.AsyncTask$Frame$FrameData: Async frame data: Test Connection -> Prepare connection -> Establish database connection -> Get database credentials -> Perform database connection
2022-04-18 14:58:16,019 [ 59270] INFO - #c.i.e.r.RemoteProcessSupport - Terminating: 127.0.0.1:58696/RemoteDriverImpld6de775c
2022-04-18 14:58:16,054 [ 59305] INFO - #c.i.e.r.RemoteProcessSupport - Process finished with exit code -1
更新: Windows 用の「MySQL Workbench」を試してみたところ、不思議なことにすぐに機能しました。他のクライアントをもう一度試してみましたが、どれも正常に接続できませんでした。これは単なる回避策であり、元の問題を解決したり明らかにしたりするものではないため、回答として追加しません。