如何实现Power BI连接仅允许本地访问的远程MySQL数据库?
Hey there! Let's tackle your two Power BI + MySQL connection scenarios step by step—super doable once you know the tricks.
1. Connecting Power BI to Local MySQL
This one's straightforward, but you need to make sure you have the right driver first:
- First, install the MySQL ODBC Driver (match the 32/64-bit version to your Power BI installation). Power BI relies on this driver to talk to MySQL. After installing, restart Power BI to pick up the driver.
- Open Power BI Desktop, click
Get Data>More, search for "MySQL", selectMySQL Database, and hitConnect. - In the connection window, enter
localhostor127.0.0.1as the server,3306as the port (use your custom port if you changed MySQL's default), then type in your database name. ClickOK. - Choose
Databaseauthentication, enter your local MySQL username and password, then clickConnect. - Once the data preview loads, select the tables/views you need, then click
Load(orTransform Dataif you want to clean up the data first). You're all set!
2. Connecting Power BI to a Remote MySQL That Only Allows Local Access (No SSH Support in Power BI)
Since Power BI doesn't have built-in SSH tunneling, we'll create a local "bridge" using an SSH tunnel tool—this makes Power BI think it's connecting to a local MySQL instance, while the traffic actually routes to the remote server. Here are two reliable methods:
Method 1: Use OpenSSH (Built into Windows 10/11)
No extra software needed—perfect for modern Windows systems:
- Open Windows Terminal (CMD or PowerShell) and run this command (replace placeholders with your details):
ssh -L 3307:127.0.0.1:3306 your_remote_ssh_username@remote_server_public_ip- Breakdown:
3307is a free local port (pick any unused one),127.0.0.1:3306is the remote MySQL's local address/port,your_remote_ssh_usernameis your SSH login for the remote server, andremote_server_public_ipis the server's public IP.
- Breakdown:
- Enter your remote SSH password when prompted. Keep this terminal window open—closing it will drop the tunnel.
- Now go back to Power BI and follow the local connection steps, but use
localhostas the server and3307as the port. Enter the remote MySQL's username and password (not the SSH ones) and connect. Power BI will route traffic through the tunnel to the remote database.
Method 2: Use PuTTY (For Older Windows Versions)
If you don't have OpenSSH, PuTTY is a classic free tool:
- Open PuTTY, go to the
Sessiontab, enter your remote server's public IP and SSH port (default is 22). - Navigate to
Connection>SSH>Tunnelsin the left menu. InSource port, enter your local port (e.g., 3307). InDestination, enter127.0.0.1:3306, then clickAdd. - Go back to
Session, save this configuration (so you don't have to re-enter it later), then clickOpen. - Enter your remote SSH username and password to establish the tunnel. Keep the PuTTY window open.
- Connect Power BI using
localhost:3307, with your remote MySQL credentials—same as the OpenSSH method.
Quick Notes to Avoid Headaches
- Make sure your remote server's SSH port (usually 22) is open in its firewall, and your local IP is allowed to connect to it.
- Check if your chosen local port is unused with
netstat -ano | findstr :3307(replace 3307 with your port). - If the remote MySQL is bound to an internal server IP (not 127.0.0.1), update the
Destinationin the tunnel command to that internal IP:port. - For long-term tunnels, you can set up a Windows service to run the SSH command in the background (tools like NSSM work great for this).
内容的提问来源于stack exchange,提问作者Stefano Maglione
相关产品推荐
相关产品推荐

