MySQL Driver
MySQL Driver
| Module | mysql |
| Author | Luma Contributors |
| Version | 0.1.0 |
| License | MIT |
A pure Luma MySQL/MariaDB driver. No external dependencies — it implements the MySQL text protocol directly over TCP using Luma’s buffer, crypto, and bit standard libraries.
Features
- mysql_native_password authentication
- caching_sha2_password authentication (fast-auth and full-auth)
- AuthSwitchRequest handling
- Text protocol queries (
COM_QUERY) - DSN connection strings (
user:pass@host:port/database) - String escaping for safe query interpolation
- Works with both MySQL and MariaDB
Quick Start
mysql = import "mysql"
// Open a connection
conn = db.open(mysql, "root:secret@localhost:3306/mydb")
// Run a query
rows = conn.query("SELECT id, name FROM users")
rows.walk(row) -> {
name: str = row.get("name")
print(name)
}
// Execute a statement
conn.exec("INSERT INTO users (name) VALUES ('Alice')")
// Close the connection
conn.close()Installation
- Download the module file: mysql.luma
- Place it in your project directory (or a
lib/folder) - Import it in your code:
mysql = import "mysql"DSN Format
The connection string follows the format user:password@host:port/database:
"root:@localhost:3306/mydb" // no password
"admin:secret@db.host:3306/prod" // full credentialsAPI Reference
| Function | Description |
|---|---|
connect(dsn: str) -> MysqlConn |
Open a connection to the database |
query(conn, sql: str) -> [{str: str}] |
Execute a SELECT and return rows as maps |
exec(conn, sql: str) -> [int] |
Execute INSERT/UPDATE/DELETE, return [affected_rows, last_insert_id] |
disconnect(conn) |
Send COM_QUIT and close the connection |
escape(value: str) -> str |
Escape a string for safe SQL interpolation |
For a full guide on using databases in Luma, see the Database documentation.