Skip to content

MySQL

MySQL is a widely-used open-source relational database management system known for its performance, reliability, and ease of use. Hyperterse provides full support for MySQL with connection pooling, character set configuration, transaction support, and all standard SQL features including joins, aggregations, and subqueries.

MySQL adapters use the Go MySQL driver connection format:

adapters:
my_mysql:
connector: mysql
connection_string: 'user:password@tcp(host:3306)/database'

Add parameters to the connection string for fine-tuning:

connection_string: 'user:pass@tcp(host:3306)/db?charset=utf8mb4&parseTime=true&loc=UTC&timeout=10s'

Configure connection pooling and other settings:

adapters:
production_db:
connector: mysql
connection_string: 'user:pass@tcp(host:3306)/db'
options:
max_connections: '10'
charset: 'utf8mb4'

For a complete list of connection parameters, see the MySQL connection documentation.

It is very easy to set up a database for Hyperterse. You can use your existing database or create a new one and wire it up to Hyperterse.

  1. Create database and user

    Create a dedicated database and user for Hyperterse:

    CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    CREATE USER 'hyperterse'@'%' IDENTIFIED BY 'secure_password';
    GRANT SELECT ON myapp.* TO 'hyperterse'@'%';
    FLUSH PRIVILEGES;

    Adjust the host (% allows any host) based on your security requirements. For local-only access, use 'hyperterse'@'localhost'.

  2. Grant permissions

    Grant only the permissions needed for your use case:

    -- Read-only access
    GRANT SELECT ON myapp.* TO 'hyperterse'@'%';
    -- For write operations
    GRANT INSERT, UPDATE, DELETE ON myapp.* TO 'hyperterse'@'%';
    -- For specific tables only
    GRANT SELECT ON myapp.users, myapp.products TO 'hyperterse'@'%';
  3. Configure Hyperterse

    Add the MySQL adapter to your configuration:

    adapters:
    main_db:
    connector: mysql
    connection_string: 'hyperterse:secure_password@tcp(localhost:3306)/myapp?charset=utf8mb4&parseTime=true'
    options:
    max_connections: '10'
  4. Verify connection

    Test the connection using the development server:

    Terminal window
    hyperterse dev -f config.terse

    Look for a successful connection message:

    INFO Connected to adapter: main_db

MySQL queries in Hyperterse support all standard SQL features. Use parameterized queries with input variables for safe execution:

queries:
get-product:
use: main_db
description: 'Retrieve product by ID'
statement: |
SELECT id, name, price, description
FROM products
WHERE id = {{ inputs.productId }}
inputs:
productId:
type: int
description: 'Product ID'

MySQL-specific features like JSON functions, window functions, and stored procedures are fully supported. Use standard MySQL syntax in your query statements.

Hyperterse inherently does not limit any performance optimizations. You can optimize your queries and database to whatever degree MySQL allows.

For read-heavy workloads, you can configure separate adapters for primary and replica databases:

adapters:
primary:
connector: mysql
connection_string: '{{ env.PRIMARY_DB_URL }}'
replica:
connector: mysql
connection_string: '{{ env.REPLICA_DB_URL }}'

Route read queries to the replica and write queries to the primary.

Verify user permissions:

-- Check grants
SHOW GRANTS FOR 'hyperterse'@'%';
-- Grant if needed
GRANT SELECT ON myapp.* TO 'hyperterse'@'%';
FLUSH PRIVILEGES;

Ensure the user exists and has the correct host permissions.

Ensure UTF-8 support by using utf8mb4 charset:

connection_string: 'user:pass@tcp(host:3306)/db?charset=utf8mb4'

Also verify the database and table character sets:

SHOW CREATE DATABASE myapp;
SHOW CREATE TABLE table_name;

Increase timeout values in the connection string:

connection_string: 'user:pass@tcp(host:3306)/db?timeout=30s&readTimeout=30s&writeTimeout=30s'

Check network connectivity and MySQL server status if timeouts persist.

Set the timezone explicitly for consistent datetime handling:

connection_string: 'user:pass@tcp(host:3306)/db?parseTime=true&loc=UTC'

This ensures datetime values are parsed consistently regardless of server timezone settings.