MySQL CLI

A standalone, feature-rich MySQL interactive CLI client for Go applications.
Features
- 🚀 Full MySQL protocol support
- 🔧 Customizable connection parameters
- 💾 Connection pooling and timeout control
- 🔒 TLS/SSL support
- 🌍 Charset and timezone configuration
- 📊 Vertical and horizontal display modes
- ⏱️ Query timing
- 🔄 Transaction support
- 📝 Multi-line SQL input
- 🎨 Syntax highlighting support
Installation
go get github.com/binrchq/mysql-cli
Quick Start
package main
import (
"log"
"os"
mysqlcli "github.com/binrchq/mysql-cli"
)
func main() {
cli := mysqlcli.NewCLI(
os.Stdin, // terminal reader
"localhost", // host
3306, // port
"root", // username
"password", // password
"mydb", // database
)
if err := cli.Connect(); err != nil {
log.Fatal(err)
}
defer cli.Close()
if err := cli.Start(); err != nil {
log.Fatal(err)
}
}
Advanced Configuration
config := &mysqlcli.Config{
Host: "localhost",
Port: 3306,
Username: "root",
Password: "password",
Database: "mydb",
Charset: "utf8mb4",
Timeout: 15 * time.Second,
ReadTimeout: 60 * time.Second,
MaxOpenConns: 20,
MaxIdleConns: 10,
ConnMaxLifetime: 2 * time.Hour,
TLS: "skip-verify",
CustomParams: "autocommit=1",
}
cli := mysqlcli.NewCLIWithConfig(terminal, config)
Configuration Options
| Option |
Type |
Default |
Description |
| Host |
string |
- |
MySQL server host |
| Port |
int |
3306 |
MySQL server port |
| Username |
string |
- |
MySQL username |
| Password |
string |
- |
MySQL password |
| Database |
string |
- |
Database name |
| Charset |
string |
utf8mb4 |
Character set |
| Collation |
string |
- |
Collation |
| Timeout |
duration |
10s |
Connection timeout |
| ReadTimeout |
duration |
30s |
Read timeout |
| WriteTimeout |
duration |
30s |
Write timeout |
| MaxOpenConns |
int |
10 |
Max open connections |
| MaxIdleConns |
int |
5 |
Max idle connections |
| ConnMaxLifetime |
duration |
1h |
Connection max lifetime |
| ParseTime |
bool |
true |
Parse time values |
| Loc |
string |
Local |
Timezone location |
| TLS |
string |
- |
TLS configuration |
| CustomParams |
string |
- |
Custom DSN parameters |
Supported Commands
SQL Commands
SELECT, INSERT, UPDATE, DELETE
CREATE TABLE, ALTER TABLE, DROP TABLE
CREATE INDEX, DROP INDEX
- All standard MySQL SQL syntax
Special Commands
help, \h - Show help
exit, quit, \q - Exit CLI
\c - Cancel current command
\s - Show server status
\d, \db - Show current database
\u <db>, \use <db> - Switch database
\G - Display results vertically
timing - Toggle timing display
Transaction Commands
BEGIN, START TRANSACTION - Start transaction
COMMIT - Commit transaction
ROLLBACK - Rollback transaction
Examples
See the example directory for complete examples.
Requirements
- Go 1.21 or higher
- MySQL 5.7 or higher
Dependencies
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Author
Maintained by binrc.