> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/integrations/builtin/credentials/mysql.md).

# MySQL credentials

You can use these credentials to authenticate the following nodes:

* [MySQL](https://github.com/n8n-io/n8n-docs/blob/main/docs/integrations/builtin/app-nodes/n8n-nodes-base.mysql)
* [Agent](https://github.com/n8n-io/n8n-docs/blob/main/docs/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent)

{% hint style="info" %}
**Agent node users**

The Agent node doesn't support SSH tunnels.
{% endhint %}

## Prerequisites <a href="#prerequisites" id="prerequisites"></a>

Create a user account on a [MySQL](https://www.mysql.com/) server database.

## Supported authentication methods <a href="#supported-authentication-methods" id="supported-authentication-methods"></a>

* Database connection

## Related resources <a href="#related-resources" id="related-resources"></a>

Refer to [MySQL's documentation](https://dev.mysql.com/doc/refman/8.3/en/) for more information about the service.

## Using database connection <a href="#using-database-connection" id="using-database-connection"></a>

To configure this credential, you'll need:

* The server **Host**: The database's host name or IP address.
* The **Database** name.
* A **User** name.
* A **Password** for that user.
* The **Port** number used by the MySQL server.
* **Connect Timeout**: The number of milliseconds during the initial database connection before a timeout occurs.
* **SSL**: If your database is using SSL, turn this on and add details for the SSL certificate.
* **SSH Tunnel**: Choose whether to connect over an SSH tunnel. An SSH tunnel lets un-encrypted traffic pass over an encrypted connection and enables authorized remote access to servers protected from outside connections by a firewall.

To set up your database connection credential:

1. Enter your database's hostname as the **Host** in your n8n credential. Run this query to confirm the hostname:

   ```
   SHOW VARIABLES WHERE Variable_name = 'hostname';
   ```
2. Enter your database's name as the **Database** in your n8n credential. Run this query to confirm the database name:

   ```
   SHOW DATABASES;
   ```
3. Enter the username of a **User** in the database. This user should have appropriate permissions for whatever actions you want n8n to perform.
4. Enter the **Password** for that user.
5. Enter the **Port** number used by the MySQL server (default is `3306`). Run this query to confirm the port number:

   ```
   SHOW VARIABLES WHERE Variable_name = 'port';
   ```
6. Enter the **Connect Timeout** you'd like the node to use. The Connect Timeout is the number of milliseconds during the initial database connection the node should wait before timing out. n8n defaults to `10000` which is the default used by MySQL of 10 seconds. If you want to match your database's `connect_timeout`, run this query to get it, then multiply by 1000 before entering it in n8n:

   ```
   SHOW VARIABLES WHERE Variable_name = 'connect_timeout';
   ```
7. If your database uses SSL and you'd like to use **SSL** for the connection, turn this option on in the credential. If you turn it on, enter the information from your MySQL SSL certificate in these fields:
   1. Enter the `ca.pem` file contents in the **CA Certificate** field.
   2. Enter the `client-key.pem` file contents in the **Client Private Key** field.
   3. Enter the `client-cert.pem` file contents in the **Client Certificate** field.
8. If you want to use **SSH Tunnel** for the connection, turn this option on in the credential. Otherwise, skip it. If you turn it on:
   1. Select the **SSH Authenticate with** to set the SSH Tunnel type to build:
      * Select **Password** if you want to connect to SSH using a password.
      * Select **Private Key** if you want to connect to SSH using an identity file (private key) and a passphrase.
   2. Enter the **SSH Host**. n8n uses this host to create the SSH URI formatted as: `[user@]host:port`.
   3. Enter the **SSH Port**. n8n uses this port to create the SSH URI formatted as: `[user@]host:port`.
   4. Enter the **SSH User** to connect with. n8n uses this user to create the SSH URI formatted as: `[user@]host:port`.
   5. If you selected **Password** for **SSH Authenticate with**, add the **SSH Password**.
   6. If you selected **Private Key** for **SSH Authenticate with**:
      1. Add the contents of the **Private Key** or identity file used for SSH. This is the same as using the `ssh-identity-file` option with the `shell-connect()` command in MySQL.
      2. If the **Private Key** was created with a passphrase, enter that **Passphrase**. This is the same as using the `ssh-identity-pass` option with the `shell-connect()` command in MySQL. If the **Private Key** has no passphrase, leave this field blank.

Refer to [MySQL | Creating SSL and RSA Certificates and Keys](https://dev.mysql.com/doc/refman/8.0/en/creating-ssl-rsa-files.html) for more information on working with SSL certificates in MySQL. Refer to [MySQL | Using an SSH Tunnel](https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-connection-ssh.html) for more information on working with SSH tunnels in MySQL.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.n8n.io/integrations/builtin/credentials/mysql.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
