# MySQL & MariaDB

Type: `state.mysql`

Status: stable

Reference: https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-mysql/

## Example

```
apiVersion: cra.diagrid.io/v1beta1
kind: Component
metadata:
  name: <name>
spec:
  type: state.mysql
  version: v1
  metadata:
    # The connection string to connect to MySQL. Do not add the schema to the connection string.
    - name: connectionString
      value: "<user>:<password>@tcp(<server>:3306)/?allowNativePasswords=true&tls=custom"
    # Use this state store for actors. Defaults to `false`. (Optional)
    #- name: actorStateStore
    #  value: "false"
    # Interval at which entries with TTL are cleaned up. (Optional)
    #- name: cleanupInterval
    #  value: "1h"
    # Prefix added to keys in the state store. (Optional)
    #- name: keyPrefix
    #  value: "appid"
    # Name of the table Dapr uses to store a few metadata properties (Optional)
    #- name: metadataTableName
    #  value: "dapr_metadata"
    # By setting outboxDiscardWhenMissingState to true, Dapr discards the transaction if it cannot find the state in the database and does not retry. This setting can be useful if the state store data has been deleted for any reason before Dapr was able to deliver the message and you would like Dapr to drop the items from the pub/sub and stop retrying to fetch the state (Optional)
    #- name: outboxDiscardWhenMissingState
    #  value: "false"
    # For outbox. Sets the name of the pub/sub component to deliver the notifications when publishing state changes (Optional)
    #- name: outboxPublishPubsub
    #  value: ""
    # For outbox. Sets the topic that receives the state changes on the pub/sub configured with "outboxPublishPubsub". The message body will be a state transaction item for an insert or update operation (Optional)
    #- name: outboxPublishTopic
    #  value: ""
    # For outbox. Sets the pub/sub component used by Dapr to coordinate the state and pub/sub transactions. If not set, the pub/sub component configured with "outboxPublishPubsub" is used. This is useful if you want to separate the pub/sub component used to send the notification state changes from the one used to coordinate the transaction (Optional)
    #- name: outboxPubsub
    #  value: "outboxPublishPubsub"
    # The schema name (database) to use. Will be created if schema does not exist. (Optional)
    #- name: schemaName
    #  value: "dapr_state_store"
    # The table name to use. Will be created if table does not exist. (Optional)
    #- name: tableName
    #  value: "state"
    # Timeout for all database operations (in seconds). (Optional)
    #- name: timeoutInSeconds
    #  value: "20"

```

## Authentication profiles

Available authentication profiles:

- Connection string

### Connection string

Authenticate using a connection string.

#### `connectionString`

**Required** - The connection string to connect to MySQL. Do not add the schema to the connection string.

Example value: `<user>:<password>@tcp(<server>:3306)/?allowNativePasswords=true&tls=custom`

## Metadata

### `actorStateStore` (bool)

Use this state store for actors. Defaults to `false`.

Example value: `false`

### `cleanupInterval` (duration)

Interval at which entries with TTL are cleaned up.

Default value: `1h`

Example value: `20m`

### `keyPrefix` (string)

Prefix added to keys in the state store.

Default value: `appid`

Example value: `appid`

Allowed values:

- appid

- name

- none

Documentation: https://docs.dapr.io/developing-applications/building-blocks/state-management/howto-share-state/

### `metadataTableName` (string)

Name of the table Dapr uses to store a few metadata properties

Default value: `dapr_metadata`

Example value: `dapr_metadata`

### `outboxDiscardWhenMissingState` (bool)

By setting outboxDiscardWhenMissingState to true, Dapr discards the transaction if it cannot find the state in the database and does not retry. This setting can be useful if the state store data has been deleted for any reason before Dapr was able to deliver the message and you would like Dapr to drop the items from the pub/sub and stop retrying to fetch the state

Default value: `false`

### `outboxPublishPubsub` (string)

For outbox. Sets the name of the pub/sub component to deliver the notifications when publishing state changes

### `outboxPublishTopic` (string)

For outbox. Sets the topic that receives the state changes on the pub/sub configured with "outboxPublishPubsub". The message body will be a state transaction item for an insert or update operation

### `outboxPubsub` (string)

For outbox. Sets the pub/sub component used by Dapr to coordinate the state and pub/sub transactions. If not set, the pub/sub component configured with "outboxPublishPubsub" is used. This is useful if you want to separate the pub/sub component used to send the notification state changes from the one used to coordinate the transaction

Default value: `outboxPublishPubsub`

### `schemaName` (string)

The schema name (database) to use. Will be created if schema does not exist.

Default value: `dapr_state_store`

Example value: `custom_schema`

### `tableName` (string)

The table name to use. Will be created if table does not exist.

Default value: `state`

Example value: `table_name`

### `timeoutInSeconds` (number)

Timeout for all database operations (in seconds).

Default value: `20`

Example value: `30`
