MySQL

Definition

A MySQL Resource is defined in convox.yml and linked to one or more Services.

resources:
  database:
    type: mysql
services:
  web:
    resources:
      - database

Containerized Options

By default, Convox runs MySQL as a container inside your Rack. This is fast to set up and ideal for development and staging environments.

resources:
  database:
    type: mysql
    options:
      version: "8.4"
      storage: 20
      mem: 512
Attribute Type Default Description
version string 8.4 The MySQL Docker image tag. The default applies when the Resource is created
storage int 10 The amount of persistent storage (in GB)
cpu int CPU request and limit for the container, in millicores
mem int Memory request and limit for the container, in MiB

On Rack version 3.26.0 or later, a new Resource without version runs 8.4. An existing Resource keeps the version it runs, which is 5.7.23 for a Resource created with the earlier default. See Containerized Versions to move to a newer version.

  • MySQL 8.4 creates the root user with caching_sha2_password, where 5.7 used mysql_native_password. Clients without caching_sha2_password support, such as the Node mysql package, cannot connect; mysql2 and current connectors can.
  • When mem is set, give MySQL 8.4 about 512. At 256 or 384 it is killed for running out of memory during initialization.
  • convox resources console, export and import cannot connect to 5.7.23, which offers only TLS 1.0 and 1.1. On an existing Resource still on 5.7.23, set version: "5.7" first: the Resource moves to 5.7.44 on the same volume, and those commands then work.

AWS RDS Managed MySQL Resources

Convox allows the creation of MySQL resources via AWS RDS. This provides enhanced durability, automated backups, and managed service benefits. Use rds-mysql as the resource type:

resources:
  database:
    type: rds-mysql
    options:
      class: db.m5.large
      storage: 100
      version: "8.0"
      deletionProtection: true
      durable: true
      encrypted: true
      backupRetentionPeriod: 7
      preferredBackupWindow: 02:00-03:00
      preferredMaintenanceWindow: sun:05:00-sun:06:00
services:
  web:
    resources:
      - database

RDS Features

  • Read Replica Support: Configure read replicas for improved read scalability and reliability. Read replicas can be promoted to active primaries if needed.
  • Import Existing RDS Database: Import existing AWS RDS databases into a Convox rack for management or access via linking.

RDS Configuration Options

Attribute Type Default Description
class string Required The compute and memory capacity of the DB instance (e.g., db.t3.micro, db.m5.large). Required for a primary; a read replica defaults to the source's class
version string Required The version of the database engine (e.g., 8.0, 8.4). Not accepted on a read replica, which runs the source's version
storage int 20 The amount of storage (in GB) to allocate for the DB instance. A read replica defaults to the source's storage and cannot be smaller
encrypted boolean false Whether to enable storage encryption. Immutable after creation
deletionProtection boolean false Whether to enable deletion protection for the DB instance
durable boolean false Whether to create a Multi-AZ DB instance for high availability
backupRetentionPeriod int 1 The number of days for which automated backups are retained. Set to 0 to disable automated backups
preferredBackupWindow string AWS managed The daily time range for automated backups in UTC (format: hh24:mi-hh24:mi, at least 30 minutes)
preferredMaintenanceWindow string AWS managed The weekly time range for system maintenance in UTC (format: ddd:hh24:mi-ddd:hh24:mi)
iops int The amount of provisioned IOPS
port int 3306 The port on which the database accepts connections. Immutable after creation
masterUserPassword string Convox generated The password for the master user. Set as an environment variable to avoid hardcoding
allowMajorVersionUpgrade boolean true Whether major version upgrades are allowed
autoMinorVersionUpgrade boolean true Whether minor version upgrades are applied automatically
readSourceDB string Makes this Resource a read replica of #convox.resources.<name> (an RDS Resource in the same App, Rack version 3.26.1 or later) or of an RDS instance identifier or ARN. See Read Replicas
import string The database identifier for importing an existing RDS instance. Requires masterUserPassword

Command Line Interface

Listing Resources

$ convox resources -a myapp
NAME      TYPE       URL
database  rds-mysql  mysql://username:password@host.name:port/database

Getting Information about a Resource

$ convox resources info database -a myapp
Name  database
Type  rds-mysql
URL   mysql://username:password@host.name:port/database

Getting the URL for a Resource

$ convox resources url database -a myapp
mysql://username:password@host.name:port/database

Launching a Console

$ convox resources console database -a myapp
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.36 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Starting a Proxy to a Resource

$ convox resources proxy database -a myapp
Proxying localhost:3306 to host.name:port

Proxying allows you to connect tools on your local machine to Resources running inside the Rack.

Exporting Data from a Resource

$ convox resources export database -f /tmp/db.sql
Exporting resource data... OK

Importing Data to a Resource

$ convox resources import database -f /tmp/db.sql
Importing resource data... OK

A file exported on a Rack before 3.26.0 starts with the line mysqldump: [Warning] Using a password on the command line interface can be insecure., and importing it fails at that line. Delete the line before importing. Files exported on Rack version 3.26.0 or later import as they are.