Mysql

A clearskies MySQL cursor.

  1. Overview
  2. hostname
  3. username
  4. password
  5. database
  6. autocommit
  7. connect_timeout
  8. port
  9. cert_path
  10. port_forwarding

Overview

This class provides a MySQL cursor implementation with support for connection configuration, port forwarding, and SQL formatting.

Configuration

The following parameters are available (with their default values):

  • hostname: Hostname of the MySQL server (localhost)
  • username: Username for authentication (root)
  • password: Password for authentication ("")
  • database: Name of the database (example)
  • port: Port number (defaults to 3306 if not specified)
  • cert_path: Path to SSL certificate (optional)
  • autocommit: Whether to autocommit transactions (True)
  • connect_timeout: Connection timeout in seconds (2)
  • port_forwarding: Optional port forwarding configuration (see below)

Port Forwarding

The port_forwarding parameter accepts an instance of a subclass of PortForwarder, enabling SSM or SSH-based port forwarding if required.

Example

from clearskies.cursors.port_forwarding.ssm import SSMPortForwarder
import clearskies

cursor = clearskies.cursors.Mysql(
    hostname="db.internal",
    username="admin",
    password="secret",
    database="mydb",
    port_forwarding=SSMPortForwarder(
        instance_id="i-1234567890abcdef0",
        region="eu-west-1",
    ),
)
cursor.execute("SELECT * FROM users")
results = cursor.fetchall()

hostname

Optional

Hostname of the MySQL server.

username

Optional

Username for authentication.

password

Optional

Password for authentication.

database

Optional

Name of the database to connect to.

autocommit

Optional

Whether to automatically commit transactions.

connect_timeout

Optional

Connection timeout in seconds.

port

Optional

Port number for the MySQL server (defaults to 3306 if not specified).

cert_path

Optional

Path to SSL certificate (optional).

port_forwarding

Optional