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

SSH隧道连接PythonAnywhere MySQL至Tableau失败:端口与权限问题

Troubleshooting Tableau Connection to PythonAnywhere MySQL via SSH Tunnel

Let's break down why your Python code works but Tableau is throwing that access denied error, and fix it step by step.

First: Fix the MySQL Username Format (The Most Common Culprit)

PythonAnywhere uses a specific naming convention for MySQL users: it's your_pythonanywhere_username$your_db_username, not just myusername. For example, if your PythonAnywhere username is jonathanbechtel and your DB user is the default root, your full MySQL username is jonathanbechtel$root.

That's likely why you're seeing Access denied for user 'myusername'@'localhost'—you're probably entering just the short username in Tableau, while your Python code is using the full formatted one (check your info['username'] value, I bet it's the full string).

Second: Ensure Your SSH Tunnel is Properly Configured and Active

For Git Bash:

Your tunnel command is correct, but a few things to check:

  • Keep the SSH session open: The tunnel only exists while the Git Bash window is running. If you close it, the connection drops.
  • Avoid port conflicts: If you have a local MySQL server running on 3306, switch to another port like 3307 to avoid clashes:
    ssh -L 3307:jonathanbechtel.mysql.pythonanywhere-services.com:3306 jonathanbechtel@ssh.pythonanywhere.com
    
  • Verify the tunnel is working: Run telnet 127.0.0.1 3306 (or 3307) — if it connects, the tunnel is up. The TIME_WAIT state in netstat just means a previous connection is in the closing phase; as long as telnet works, the tunnel is usable.

For PuTTY:

If you're using PuTTY for tunneling, double-check these settings:

  1. Go to Connection > SSH > Tunnels
  2. Enter 3306 (or 3307) as the Source port
  3. Enter jonathanbechtel.mysql.pythonanywhere-services.com:3306 as the Destination
  4. Select Local and Auto, then click Add
  5. Log into your PythonAnywhere SSH session and keep the PuTTY window open

Third: Configure Tableau Correctly

Once your tunnel is active, set up Tableau's MySQL connection like this:

  • Server: 127.0.0.1 (use this instead of localhost to avoid DNS resolution issues)
  • Port: The port you used for your tunnel (3306 or 3307)
  • Username: The full PythonAnywhere MySQL username (e.g., jonathanbechtel$root)
  • Password: Your MySQL database password (not your PythonAnywhere SSH password)
  • Database: Your full PythonAnywhere database name (e.g., jonathanbechtel$mydatabase)

Also, make sure you're using the MySQL ODBC 8.0 Driver (match the bitness to your Tableau installation—64-bit Tableau needs 64-bit drivers, 32-bit needs 32-bit). Avoid the "MySQL Legacy" driver as it can cause compatibility issues.

Why Does the Python Code Work?

Your Python script uses the sshtunnel library which handles the port forwarding correctly, and you're passing the full formatted MySQL username via info['username']. The key difference is that Tableau was missing the full username string.

Quick Validation Steps

To rule out other issues:

  1. Test the tunnel with MySQL Workbench: Use 127.0.0.1:3306, the full username, and DB password. If it connects, the tunnel and permissions are good.
  2. Test with the MySQL command line:
    mysql -h 127.0.0.1 -P 3306 -u jonathanbechtel$root -p
    
    Enter your DB password—if you can log in, the problem is definitely in Tableau's configuration.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:35:27