如何通过SSH连接MySQL?VS Code有无适配的MySQL SSH连接扩展?
Connecting to MySQL via SSH in Visual Studio Code: Valid Extensions & Setup
Absolutely, there are reliable VS Code extensions that support SSH tunneling for MySQL connections. Here are the top options and how to use them:
1. Official MySQL Extension (by Oracle)
This is the go-to extension for MySQL management in VS Code, and it does support SSH tunnel connections (you might have missed the option if you were on an older version—make sure to update it first).
To set up the SSH connection:
- Open the extension's connection panel, click + Add Connection
- In the connection settings, scroll down to find the SSH Tunnel section and toggle it on
- Fill in your SSH server details:
- SSH Host: Your remote server IP/domain
- SSH Port: Default is 22, adjust if needed
- SSH User: Your SSH username
- Authentication method: Choose between password or private key (browse to your
.pem/.sshkey file)
- For the MySQL connection part, set Host to
localhost(since the SSH tunnel forwards the remote MySQL port to your local machine) - Fill in your MySQL username, password, and the remote MySQL port (usually 3306)
- Save the connection and test it—you should be connected via SSH
2. Database Client (Multi-database Extension)
If you work with multiple databases beyond MySQL, this third-party extension is a great all-in-one tool with straightforward SSH support:
- Install the extension, open its connection sidebar
- Click New Connection and select MySQL as the database type
- Switch to the SSH tab in the connection setup window
- Enter your SSH server credentials (host, port, user, auth method)
- Go back to the General tab, set MySQL Host to
localhost, then fill in your MySQL username, password, and port - Save and connect—this extension handles the tunnel automatically for you
Alternative: Manual SSH Port Forwarding
If you prefer not to rely on extension-specific SSH features, you can set up a local port forward via terminal first:
- Run this command in your terminal:
(This forwards your local port 3307 to the remote server's MySQL port 3306)ssh -L 3307:localhost:3306 your-ssh-user@your-ssh-server-ip - Then use any basic MySQL extension in VS Code to connect to
localhost:3307with your remote MySQL credentials
内容的提问来源于stack exchange,提问作者lrnzfrr
相关产品推荐
相关产品推荐

