Skip to content

Connect Go to SQLEye

Use a pgx connection URL for PostgreSQL and a tcp(127.0.0.1:port) DSN for MySQL. Create the database first, see CLI clients. Replace the ports with your instance’s port.

pgx’s pgx.Connect and pgxpool.New accept PostgreSQL connection URLs.

import (
"context"
"github.com/jackc/pgx/v5"
)
conn, err := pgx.Connect(context.Background(), "postgres://postgres@127.0.0.1:5432/myapp")

The go-sql-driver DSN has the form username:password@protocol(address)/dbname, and TCP addresses are host[:port].

import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
db, err := sql.Open("mysql", "root@tcp(127.0.0.1:3306)/myapp")

Sources: pgx, go-sql-driver/mysql. To see what your Go code sends, turn on capture.

SQLEye is developed and maintained by CodeROG. This page is also available as Markdown.