# Create a MySQL instance

Create a MySQL instance.

[endpoint]
method = "POST"
base_url = "https://{availability_zone}.betterstackcloud.com"
path = "/v1/mysql"

[[body_param]]
name = "name"
required = true
type = "string"
description = "The instance's name, at most 255 characters. Must be unique among your organization's MySQL instances that aren't destroyed or failed."

[[body_param]]
name = "type"
required = true
type = "string"
description = "The instance's type, such as `MY1`. List the types with `betterstack mysql-type list`. To change it later, rescale the instance."

[[body_param]]
name = "team_id"
required = true
type = "string"
description = "The ID of the team that owns the instance. `betterstack team list` shows it. Can't be changed after the instance is created."

[[body_param]]
name = "engine_version"
type = "string"
description = "The MySQL version, as major and minor, such as `9.7`. List the versions with `betterstack mysql-version list`. Defaults to the latest version. To change it later, upgrade the instance."

[[body_param]]
name = "sql_mode"
type = "string or null"
description = "The SQL modes, separated by commas, such as `STRICT_TRANS_TABLES,NO_ZERO_DATE`. Is `null` for MySQL's default modes."

[[body_param]]
name = "sql_require_primary_key"
default = "false"
type = "boolean"
description = "Whether new tables must have a primary key."

[[body_param]]
name = "default_time_zone"
default = "UTC"
type = "string"
description = "The default time zone. Accepts `SYSTEM`, `UTC`, an offset from `-13:59` to `+14:00`, or an IANA time zone name such as `Europe/Prague`."

[[body_param]]
name = "max_allowed_packet"
default = "67108864"
type = "integer"
description = "The largest packet MySQL accepts, in bytes, from 16777216 to 1073741824."

[[body_param]]
name = "public_access"
default = "false"
type = "boolean"
description = "Whether the instance is also reachable on public IP addresses. Clients must connect with TLS."

[[body_param]]
name = "replica_count"
default = "0"
type = "integer"
description = "The number of read replicas, from 0 to 2."

[[body_param]]
name = "network_ids"
type = "array of strings"
description = "The IDs of your networks attached to every member. Each network must be in the instance's team. To change the networks later, attach or detach a network. Order doesn't matter."

[[body_param]]
name = "firewall_ids"
type = "array of strings"
description = "The ID of the firewall attached to every member. An instance can have one firewall. To change it later, attach or detach a firewall. Order doesn't matter."

[[body_param]]
name = "term"
default = "monthly"
type = "string"
description = "The billing term. Defaults to `monthly`. A change applies at once, from `monthly` to `annual` or back. Billing ends the current term and starts the new one. Sending the current term changes nothing.<br/>Valid values:<br/>`monthly`: Billed every month.<br/>`annual`: Paid for a year."

[[body_param]]
name = "metadata"
type = "object"
description = "Your tags, as an object of string keys and values. An update replaces every tag. Accepts any keys."

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"

[[header]]
name = "Content-Type"
description = "application/json"
required = false
type = "string"
[/endpoint]

[responses]
[[response]]
status = 202
description = "Returns the newly created MySQL instance."
body = '''
{
  "id": "example",
  "name": "Example MySQL instance",
  "type": "MY1",
  "usable_disk_gb": 1,
  "max_connections": 1,
  "engine_version": "1.4.2",
  "engine_patch_version": "1.4.2",
  "available_engine_versions": [
    "1.4.2"
  ],
  "status": "provisioning",
  "status_message": "example",
  "sql_mode": "example",
  "sql_require_primary_key": false,
  "default_time_zone": "UTC",
  "max_allowed_packet": 67108864,
  "public_access": false,
  "replica_count": 0,
  "read_only": false,
  "endpoint": {
    "hostname": "proxy.example.com",
    "public_hostname": "proxy.example.com",
    "port": 443,
    "private_ips": [
      {
        "network_id": "123456789",
        "ip_address": "example"
      }
    ],
    "public_ips": [
      {
        "ip": "example",
        "type": "example"
      }
    ]
  },
  "members": [
    {
      "id": "example",
      "role": "primary",
      "status": "provisioning",
      "replication_lag_seconds": 1.5,
      "disk_used_bytes": 1,
      "private_ips": [
        {
          "network_id": "123456789",
          "ip_address": "example"
        }
      ],
      "created_at": "2026-07-01T12:00:00.000Z"
    }
  ],
  "network_ids": [
    "123456789"
  ],
  "firewall_ids": [
    "123456789"
  ],
  "latest_snapshot_at": "2026-07-01T12:00:00.000Z",
  "term": "monthly",
  "created_at": "2026-07-01T12:00:00.000Z",
  "updated_at": "2026-07-01T12:00:00.000Z",
  "team_id": "t123",
  "metadata": {
    "example": "value"
  }
}
'''

[[response]]
status = 400
description = "The body isn't valid JSON."
body = '''
{
  "error": {
    "message": "Malformed JSON body.",
    "code": "bad_request"
  }
}
'''

[[response]]
status = 401
description = "The API token is missing or invalid."
body = '''
{
  "error": {
    "message": "Missing or invalid token.",
    "code": "unauthorized"
  }
}
'''

[[response]]
status = 402
description = "The organization hasn't made its first payment yet, and the request creates a resource we charge for. The code is `payment_required`. A request that creates a server, load balancer, object cache, database, reserved IP or volume can also return `first_purchase`. The `url` in `first_purchase` opens a page where you make the payment. The resource is created after the payment. The page works until `expires_at`, 24 hours after the response."
body = '''
{
  "error": {
    "message": "We require at least one successful credit card transaction before allowing billable actions via the API. This significantly helps us to prevent fraud. Once your first transaction is processed, you will be able to use the API unrestricted. Please add credit to your account at https://betterstack.com/settings/billing/card/new?credits=10&activate_api=true. Need help? We're here for you at hello@betterstack.com.",
    "code": "payment_required"
  }
}
'''

[[response]]
status = 403
description = "The organization has reached its limit of MySQL instances. The error code is `quota_exceeded`."

[[response]]
status = 404
description = "The team, type, network or firewall you sent doesn't exist, or the token can't access it."

[[response]]
status = 409
description = "The resource's state doesn't allow the request, such as starting a running server or removing a placement group that still has servers."

[[response]]
status = 422
description = "A value isn't valid, with the code `validation_failed`. The error's `details` list the messages for each field. A create or rescale that names a deprecated type with a replacement returns the code `type_deprecated`. The error's `details` then name the field, the deprecated type and its `replacement`."

[[response]]
status = 423
description = "We've locked the resource, with the code `locked`. Every change to a locked resource is refused, and so is a change that involves one."

[[response]]
status = 429
description = "Too many requests, with the code `rate_limited`. We limit requests per client IP and per organization, and some costly endpoints have a stricter limit. Wait as long as the `Retry-After` header says."

[[response]]
status = 500
description = "An unexpected, temporary error on our side, with the code `internal_error`. Try again."
body = '''
{
  "error": {
    "message": "The request could not be completed right now. Please try again in a few moments.",
    "code": "internal_error"
  }
}
'''

[[response]]
status = 503
description = "Another MySQL instance is being created in the organization at the same time. Try again shortly. The error code is `concurrent_create_limit`."

[[response]]
status = 503
description = "We couldn't start the instance. Try again shortly. The error code is `orchestration_failed`."
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "id"
type = "string"
description = "The instance's ID, a UUID."

[[param]]
name = "name"
type = "string"
description = "The instance's name, at most 255 characters."

[[param]]
name = "type"
type = "string"
description = "The instance's type, such as `MY1`. List the types with `betterstack mysql-type list`."

[[param]]
name = "usable_disk_gb"
type = "integer"
description = "The disk space for your data, in GiB."

[[param]]
name = "max_connections"
type = "integer"
description = "The most connections the instance accepts at once."

[[param]]
name = "engine_version"
type = "string"
description = "The MySQL version, as major and minor, such as `9.7`. List the versions with `betterstack mysql-version list`."

[[param]]
name = "engine_patch_version"
type = "string or null"
description = "The exact MySQL release installed, or `null` until it's known."

[[param]]
name = "available_engine_versions"
type = "array of strings"
description = "The versions you can upgrade the instance to. An upgrade can't be undone."

[[param]]
name = "status"
type = "string"
description = "The instance's state.<br/>Valid values:<br/>`provisioning`: We're starting the members and installing MySQL.<br/>`running`: The instance is ready.<br/>`degraded`: A member is down, replication is broken or the disk is almost full. `status_message` says which.<br/>`rescaling`: We're changing the instance's type.<br/>`upgrading`: We're upgrading the instance to a newer MySQL version.<br/>`restoring`: We're restoring the instance from a snapshot.<br/>`failed`: We couldn't create the instance. `status_message` says why. Create a new one instead.<br/>`destroyed`: The instance is destroyed."

[[param]]
name = "status_message"
type = "string or null"
description = "Why the instance is in its current state, such as what failed or which operation didn't finish. Is `null` when there's nothing to report."

[[param]]
name = "sql_mode"
type = "string or null"
description = "The SQL modes, separated by commas, such as `STRICT_TRANS_TABLES,NO_ZERO_DATE`. Is `null` for MySQL's default modes."

[[param]]
name = "sql_require_primary_key"
type = "boolean"
description = "Whether new tables must have a primary key."

[[param]]
name = "default_time_zone"
type = "string"
description = "The default time zone. Accepts `SYSTEM`, `UTC`, an offset from `-13:59` to `+14:00`, or an IANA time zone name such as `Europe/Prague`."

[[param]]
name = "max_allowed_packet"
type = "integer"
description = "The largest packet MySQL accepts, in bytes, from 16777216 to 1073741824."

[[param]]
name = "public_access"
type = "boolean"
description = "Whether the instance is also reachable on public IP addresses. Clients must connect with TLS."

[[param]]
name = "replica_count"
type = "integer"
description = "The number of read replicas, from 0 to 2."

[[param]]
name = "read_only"
type = "boolean"
description = "Whether the instance accepts only reads because its disk is almost full."

[[param]]
name = "endpoint"
type = "object"
description = "Where clients connect to the current primary."

[[param]]
name = "endpoint.hostname"
type = "string"
description = "The hostname to connect to from your networks. Resolves to the primary's addresses in your networks."

[[param]]
name = "endpoint.public_hostname"
type = "string or null"
description = "The hostname to connect to from the internet, or `null` when `public_access` is off. Resolves to the primary's public addresses."

[[param]]
name = "endpoint.port"
type = "integer"
description = "The port to connect to, `3306`."

[[param]]
name = "endpoint.private_ips"
type = "array of objects"
description = "The primary's addresses in your networks."

[[param]]
name = "endpoint.private_ips[].network_id"
type = "string"
description = "The ID of the network."

[[param]]
name = "endpoint.private_ips[].ip_address"
type = "string"
description = "The address in that network."

[[param]]
name = "endpoint.public_ips"
type = "array of objects"
description = "The primary's public addresses, empty when `public_access` is off."

[[param]]
name = "endpoint.public_ips[].ip"
type = "string"
description = "The public address."

[[param]]
name = "endpoint.public_ips[].type"
type = "string"
description = "Whether it's an `ipv4` or `ipv6` address."

[[param]]
name = "members"
type = "array of objects"
description = "The instance's members, the primary and its replicas. A replica's `replication_lag_seconds` says how far behind the primary it is, and it's `null` on the primary."

[[param]]
name = "members[].id"
type = "string"
description = "The id."

[[param]]
name = "members[].role"
type = "string"
description = "Possible values: `primary`, `replica`."

[[param]]
name = "members[].status"
type = "string"
description = "Possible values: `provisioning`, `syncing`, `running`, `down`."

[[param]]
name = "members[].replication_lag_seconds"
type = "number or null"
description = "The replication lag seconds."

[[param]]
name = "members[].disk_used_bytes"
type = "integer"
description = "The disk used bytes."

[[param]]
name = "members[].private_ips"
type = "array of objects"
description = "The private ips."

[[param]]
name = "members[].private_ips[].network_id"
type = "string"
description = "The network id."

[[param]]
name = "members[].private_ips[].ip_address"
type = "string"
description = "The ip address."

[[param]]
name = "members[].created_at"
type = "datetime"
description = "In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "network_ids"
type = "array of strings"
description = "The IDs of your networks attached to every member. Order doesn't matter."

[[param]]
name = "firewall_ids"
type = "array of strings"
description = "The ID of the firewall attached to every member. An instance can have one firewall. Order doesn't matter."

[[param]]
name = "latest_snapshot_at"
type = "datetime or null"
description = "When the newest available snapshot was taken, or `null` when there's none. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "term"
type = "string"
description = "The billing term. Defaults to `monthly`.<br/>Valid values:<br/>`monthly`: Billed every month.<br/>`annual`: Paid for a year."

[[param]]
name = "created_at"
type = "datetime"
description = "When the instance was created. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "updated_at"
type = "datetime"
description = "When the instance was last updated. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "team_id"
type = "string"
description = "The ID of the team that owns the instance. `betterstack team list` shows it."

[[param]]
name = "metadata"
type = "object"
description = "Your tags, as an object of string keys and values."
[/params]
