> ## Documentation Index
> Fetch the complete documentation index at: https://docs.keephq.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# MySQL

> MySQL Provider is a provider used to query MySQL databases

## Authentication

This provider requires authentication.

* **username**: MySQL username (required: True, sensitive: False)
* **password**: MySQL password (required: True, sensitive: True)
* **host**: MySQL hostname (required: True, sensitive: False)
* **database**: MySQL database name (required: False, sensitive: False)
* **port**: MySQL port (required: False, sensitive: False)

Certain scopes may be required to perform specific actions or queries via the provider. Below is a summary of relevant scopes and their use cases:

* **connect\_to\_server**: The user can connect to the server (mandatory)

## In workflows

This provider can be used in workflows.

As "step" to query data, example:

```yaml theme={null}
steps:
    - name: Query mysql
      provider: mysql
      config: "{{ provider.my_provider_name }}"
      with:
        query: {value}  # Query to execute
        as_dict: {value}  # If True, returns the results as a list of dictionaries
        single_row: {value}  # If True, returns only the first row of the results
        # Arguments will me passed to the query.format(**kwargs)
```

As "action" to make changes or update data, example:

```yaml theme={null}
actions:
    - name: Query mysql
      provider: mysql
      config: "{{ provider.my_provider_name }}"
      with:
        query: {value}  # Query to execute
        as_dict: {value}  # If True, returns the results as a list of dictionaries
        single_row: {value}  # If True, returns only the first row of the results
        # Arguments will me passed to the query.format(**kwargs)
```

Check the following workflow examples:

* [blogpost.yml](https://github.com/keephq/keep/blob/main/examples/workflows/blogpost.yml)
* [conditionally\_run\_if\_ai\_says\_so.yaml](https://github.com/keephq/keep/blob/main/examples/workflows/conditionally_run_if_ai_says_so.yaml)
* [create\_alerts\_from\_mysql.yml](https://github.com/keephq/keep/blob/main/examples/workflows/create_alerts_from_mysql.yml)
* [raw\_sql\_query\_datetime.yml](https://github.com/keephq/keep/blob/main/examples/workflows/raw_sql_query_datetime.yml)
* [simple\_http\_request\_ntfy.yml](https://github.com/keephq/keep/blob/main/examples/workflows/simple_http_request_ntfy.yml)
* [slack-message-reaction.yml](https://github.com/keephq/keep/blob/main/examples/workflows/slack-message-reaction.yml)

## Connecting with the Provider

In order to connect to the MySQL database, you will need to create a new user with the required permissions. Here's how you can do this:

1. Connect to the MySQL server as a user with sufficient privileges to create a new user.
2. Run the following command to create a new user:
   `CREATE USER '<username>'@'<host>' IDENTIFIED BY '<password>'`;
3. Grant the necessary permissions to the new user by running the following command:
   `GRANT ALL PRIVILEGES ON <database>.* TO '<username>'@'<host>'`;

## Notes

## Useful Links

* [MySQL Documentation](https://dev.mysql.com/doc/refman/8.0/en/)
