# dokploy_mysql (Resource)

A MySQL database service in a Dokploy environment.

## Example Usage

```terraform
resource "dokploy_mysql" "example" {
  name              = "app-db"
  environment_id    = [for e in dokploy_project.example.environments : e.id if e.name == "production"][0]
  database_name     = "app"
  database_user     = "app"
  database_password = var.db_password # use a sensitive variable
  docker_image      = "mysql:8"

  env = <<-EOT
    TZ=UTC
  EOT
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `database_name` (String) Name of the MySQL database.
- `database_password` (String, Sensitive) MySQL password. Changing it triggers a redeploy.
- `database_user` (String) MySQL user.
- `environment_id` (String) Id of the environment this service lives in (see `dokploy_project.environments`).
- `name` (String) Display name of the database service.

### Optional

- `app_name` (String) Dokploy-internal app name; generated by the server when omitted.
- `database_root_password` (String, Sensitive) MySQL root password. Server-generated when left unset. Changing it triggers a redeploy.
- `deploy_on_change` (Boolean) Deploy after create and after changes to deploy-triggering attributes. Defaults to `true`.
- `deployment_timeout` (String) How long to wait for a triggered deployment to reach a terminal status, as a Go duration string. Defaults to `"15m"`. On timeout the apply fails but the server-side deployment keeps running.
- `description` (String) Free-form description.
- `detach_dokploy_network` (Boolean) Detach the shared `dokploy-network` from this service. Defaults to `false`. Only meaningful together with `network_ids`; applied on the next deploy.
- `docker_image` (String) MySQL docker image, e.g. `mysql:8`. Server default when omitted.
- `env` (String) Extra environment variables in Dokploy's native multiline `KEY=value` format. Use Terraform sensitive variables for secret values. Omitting this attribute and setting it to "" are indistinguishable on read — both come back null. Use omission, not "", to clear it.
- `external_port` (Number) Host port to expose MySQL on. Unset keeps the database internal-only.
- `network_ids` (Set of String) Ids of Docker networks (Dokploy network records) to attach this service to. Applied on the next deploy. Omit to keep only the default `dokploy-network`. An empty set is not valid - omit the attribute instead.
- `server_id` (String) Remote server to run the service on. Defaults to the Dokploy host.

### Read-Only

- `created_at` (String) Creation timestamp (server-side).
- `id` (String) MySQL service id.
- `status` (String) Service status reported by Dokploy.

## Import

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
terraform import dokploy_mysql.example <mysqlId>
```