mysql

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package mysql registers an "ssh+tunnel" network type with go-mysql-driver, allowing MySQL connections to be routed through an SSH tunnel.

Import this package for its side effect:

import _ "github.com/TelpeNight/mytunnel/mysql"

Then use "ssh+tunnel" as the network in your DSN. Because the MySQL DSN parser treats "@" as a delimiter, use "(a)" in place of "@" inside the tunnel address:

db_user:db_pass@ssh+tunnel(ssh_user(a)bastion.example.com/tmp/mysql.sock?ServerAliveInterval=10)/mydb

Everything inside the parentheses is passed verbatim to dial.DialContext. When the destination address is omitted, package-level defaults match go-sql-driver/mysql: 127.0.0.1:3306 for TCP and /tmp/mysql.sock for Unix.

Example
package main

import (
	"database/sql"

	_ "github.com/TelpeNight/mytunnel/mysql"
)

func main() {
	// Importing the package registers the "ssh+tunnel" network with
	// go-mysql-driver. Use (a) in place of @ inside the tunnel address to
	// avoid conflicts with the MySQL DSN parser.
	dsn := "db_user:db_pass@ssh+tunnel(ssh_user(a)bastion.example.com/tmp/mysql.sock?ServerAliveInterval=10)/mydb"
	db, err := sql.Open("mysql", dsn)
	if err != nil {
		panic(err)
	}
	defer db.Close()

	// db is ready to use — connections are established lazily.
	_ = db
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL