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

# MySQL

> Let an AI agent query a MySQL database without holding its password.

A MySQL service lets an agent reach a MySQL database during a [session](https://infisical.com/docs/documentation/platform/agent-vault/sessions), with clients such as `mysql`. The agent never holds the password: the [proxy](https://infisical.com/docs/documentation/platform/agent-vault/proxies) logs in to the database with the service's account. The agent reaches the service through [`infisical agent-vault connect`](https://infisical.com/docs/cli/reference#agent-vault-connect).

## Prerequisites

* The [Admin role](https://infisical.com/docs/documentation/platform/agent-vault/access-control#product-membership) in your Agent Vault project
* An [access bundle](https://infisical.com/docs/documentation/platform/agent-vault/access-bundles.md) to add the service to
* A running [proxy](https://infisical.com/docs/documentation/platform/agent-vault/proxies#create-a-proxy-and-start-it) that can reach the database, and whose HTTP port the agent can reach
* An account on the database with only the access your agents need, such as a read-only database role

## Add a MySQL database

**Step 1**

In your Agent Vault project, go to **Access Bundles**. Select your access bundle, then select **Add Service**. In the **Services** list, select **Create New Service**.

**Step 2**

On the **Choose a template** panel, select the **Databases and More** tab, then select **MySQL**.

**Step 3**

On the **Details** step, enter a **Name** and the [server's details](#server-details). Select **Continue**.

**Step 4**

On the **Credential** step, set up the [account](#credentials) the proxy logs in as. Select **Continue**.

**Step 5**

Optionally, on the **Hook** step, pick the [hook](https://infisical.com/docs/documentation/platform/agent-vault/hooks.md#attach-a-hook-to-a-service) that checks each connection to this service. Select **Continue**.

**Step 6**

On the **Review** step, select **Add Service**.

Next, [connect your agent](https://infisical.com/docs/documentation/platform/agent-vault/databases-and-ssh#connect-your-agent) to the service.

## Server details

* **Name:** The name the agent connects with, as in `infisical agent-vault connect orders` (lowercase letters, numbers, and hyphens, at most 63 characters)
* **Host:** The server's host name or IP address, as the proxy reaches it, such as `orders_db` for a Docker Compose service (no scheme, port, path, or variable)
* **Port:** The server's port (defaults to `3306`)
* **Database:** The database the proxy logs in to (not a variable)
* **TLS:** How the proxy connects to the database, described in [TLS to the database](#tls-to-the-database)

A MySQL service starts in its database, but the agent can switch to any other database the account can use, so limit the account's grants to the databases the agent needs.

### TLS to the database

TLS applies only to the connection between the proxy and the database. The connection between the agent's machine and the proxy always uses TLS.

* **Use TLS** (on by default): The proxy connects to the database over TLS
* **Verify Certificate** (on by default): The proxy checks the database's certificate against the system's trusted certificate authorities, or against the CA certificate you add
* **CA Certificate (optional):** The PEM certificate of the authority that signed the database's certificate, if the database uses a private certificate (for AWS RDS, your region's bundle, such as [`us-east-1-bundle.pem`](https://truststore.pki.rds.amazonaws.com/us-east-1/us-east-1-bundle.pem))

If you turn **Use TLS** off, a MySQL service connects without TLS.

## Credentials

Enter the account's **Username** and **Password**. To give each member their own account, leave the username, the password, or both to each member, as described in [member-provided values](https://infisical.com/docs/documentation/platform/agent-vault/http-apis.md#member-provided-values). To use a password that several services share, type `{{` in **Password** and select a [variable](https://infisical.com/docs/documentation/platform/agent-vault/variables).

## Limitations

* **Database logins:** MySQL services log in with the `mysql_native_password`, `caching_sha2_password`, `sha256_password`, or `ed25519` method
* **MySQL clients need `mysql_native_password`:** The proxy offers the agent's MySQL client only the `mysql_native_password` login method, so MySQL 8 and MariaDB clients work, and newer clients built without it (such as the current Homebrew `mysql`) can't log in

## Troubleshooting

> [accordion] The client says the server closed the connection
>
> The proxy couldn't log in to the server. Check that:
>
> * The service's **Host** and **Port** are reachable from the proxy's machine
> * The account's username and password are correct
> * The TLS settings match the database, for example **Verify Certificate** is off or **CA Certificate (optional)** is set for a database with a private certificate
>
> The session's log shows the failed connection as an **Error** row with the reason, and so does the proxy's own log.
>
> If `connect` printed a message about the service's hook, the hook server refused the connection or didn't give a usable answer. See the [hook troubleshooting](https://infisical.com/docs/documentation/platform/agent-vault/hooks.md#troubleshooting).

> [accordion] The MySQL client says it can't load mysql\_native\_password
>
> The client was built without the `mysql_native_password` login method, which the proxy needs. Use a MySQL 8 or MariaDB client.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.