A simple yet powerful MySQL proxy tool written in Go that tunnels MySQL protocol traffic over WebSocket. This is particularly useful for bypassing network restrictions that limit connections to standard HTTP/WebSocket ports.
- Client-Server Architecture: Consists of a
local_clientand aserver_proxy. - TCP to WebSocket Tunneling: The client converts local TCP connections into WebSocket messages.
- WebSocket to TCP Forwarding: The server converts WebSocket messages back to TCP and forwards them to the target MySQL server.
- Configuration Driven: Easy to configure using JSON files.
- Logging: Both client and server log their activities to files.
proxy_mysql/
├── go.mod
├── go.sum
├── README.md
├── README_CN.md
├── local_client/
│ ├── config.client.json
│ └── local_client.go
└── server_proxy/
├── config.server.json
└── server_proxy.go
- Go 1.24.1+
gorilla/websocketlibrary
Before you begin, ensure you have Go installed. Then, download the required dependencies:
go mod tidyYou need to configure both the client and the server by editing their respective JSON configuration files.
{
"local_listen_address": "127.0.0.1:3307",
"server_ws_url": "ws://YOUR_SERVER_IP:16781/mysql",
"log_path": "local_client.log"
}local_listen_address: The local TCP address the client listens on. Your MySQL client (e.g., Navicat, DBeaver) will connect to this address.server_ws_url: The WebSocket URL of your remoteserver_proxy.log_path: Path to the client's log file.
{
"listen_address": "0.0.0.0:9090",
"mysql_server_address": "127.0.0.1:3306",
"log_path": "server_proxy.log"
}listen_address: The address theserver_proxylistens on for incoming WebSocket connections.mysql_server_address: The address of your actual MySQL server.log_path: Path to the server's log file.
You can compile the client and server manually for your current operating system, cross-compile for other platforms, or use the provided PowerShell script to build for all supported platforms at once.
On Windows, you can use the provided PowerShell script to compile the client and server for all target platforms (Windows, Linux, macOS).
.\build.ps1After running the script, you will find all the compiled binaries in the builds directory.
If you prefer to compile manually, follow these instructions.
======= You can compile the client and server for your current operating system or cross-compile for other platforms like Linux.
- Build
server_proxy:go build -o server_proxy ./server_proxy/
- Build
local_client:go build -o local_client ./local_client/
=======
- Build
server_proxyfor Linux:CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server_proxy_linux ./server_proxy/
- Build
local_clientfor Linux:CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o local_client_linux ./local_client/
On your server: Run the
server_proxy../server_proxy
On your local machine: Run the
local_client../local_client
Connect your MySQL client: Configure your MySQL client to connect to the
local_listen_addressspecified inconfig.client.json(e.g.,127.0.0.1:3307).
If you want to run the server_proxy behind Nginx (e.g., for SSL termination or to share port 80/443), you can use the following configuration:
server{listen16781; # Or your desired public port (e.g., 80, 443)server_name your_domain.com;location /mysql { # Forward requests to the server_proxyproxy_passhttp://127.0.0.1:9090; # Must match listen_address in config.server.json
# Required for WebSocketproxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "Upgrade";proxy_set_header Host $host; # Increase timeouts for long-lived connectionsproxy_read_timeout3600s;proxy_send_timeout3600s;}}This project is licensed under the MIT License. See the LICENSE file for details.