You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过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/.ssh key 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:
    ssh -L 3307:localhost:3306 your-ssh-user@your-ssh-server-ip
    
    (This forwards your local port 3307 to the remote server's MySQL port 3306)
  • Then use any basic MySQL extension in VS Code to connect to localhost:3307 with your remote MySQL credentials

内容的提问来源于stack exchange,提问作者lrnzfrr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:06:23