How go-sql-driver/mysql works
Go-MySQL-Driver implements Go’s database/sql driver interface. The principal workflow is an application opening the registered driver with a DSN, the driver establishing and authenticating a MySQL connection, then executing queries or prepared statements and exposing results through database/sql rows. The README also documents optional compression, time parsing, placeholder interpolation, and secure LOAD DATA LOCAL INFILE support. The map uses sampled code and README statements; some internal calls are shown as unverified where excerpts do not establish their exact wiring.
Main entry points: connection.go Connection operations · connector.go Connection setup · statement.go Prepared statements · packets.go Packet protocol
Components 17
Configuration and entry
- Driver registration
driver.go - DSN configuration
dsn.go - Connection setup
connector.go
Connection protocol
- Authentication
auth.go - Packet protocol
packets.go - Connection operations
connection.go - Collation mapping
collations.go
Query and results
- Prepared statements
statement.go - Result rows
rows.go - Column metadata
fields.go - Transactions
transaction.go
Optional capabilities
- LOCAL INFILE
infile.go - Zlib compression
compress.go - Time values
nulltime.go
Other components
- Go application
- database/sql API
- MySQL server
Connections 24
- Go application → database/sql API: uses
README.md - database/sql API → Driver registration: selects driver
README.md - database/sql API → DSN configuration: provides DSN
README.md - Driver registration → Connection setup: opens connection
- Connection setup → MySQL server: dials
connector.go - Connection setup → Authentication: authenticates
connector.go - Connection setup → Packet protocol: exchanges handshake
- Authentication → Packet protocol: sends auth packets
auth.go - Connection operations → Packet protocol: sends commands
- Connection operations → MySQL server: queries
README.md - database/sql API → Prepared statements: prepares
- Prepared statements → Packet protocol: executes prepared
- Connection operations → Result rows: returns results
- Prepared statements → Result rows: returns results
- Result rows → Column metadata: uses metadata
- Connection operations → Transactions: starts transaction
connection.go - Connection operations → LOCAL INFILE: serves file request
- Connection operations → Zlib compression: uses when enabled
- database/sql API → Time values: scans time values
README.md - DSN configuration → Zlib compression: configures option
dsn.go - DSN configuration → Collation mapping: selects collation
- Go application → LOCAL INFILE: registers allowed files
infile.go - Go application → Zlib compression: enables option
README.md - Go application → Prepared statements: uses interpolation
README.md