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

# Troubleshooting "Lost connection to MySQL server" with the ClickHouse Cloud MySQL interface

> Four things to check when a MySQL client fails with ERROR 2013 "Lost connection to MySQL server" against ClickHouse Cloud: the interface switch, the user name, the IP access list and the password type.

When a MySQL client cannot complete the handshake with a ClickHouse Cloud service, it does not show a ClickHouse error message. It reports that the connection was lost:

```text theme={null}
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 54
```

The message does not say why. Check four things: the MySQL interface is enabled for the service, the user name starts with `mysql4` and the subdomain of the service, your IP address is in the IP access list, and the password of the user is stored as `double_sha1_password`.

## How to read the message

* The text in quotes is the step of the handshake at which the client lost the connection. Both `'reading authorization packet'` and `'reading final connect information'` mean that the connection was closed before the login completed.
* The number after `system error` is an error code of the operating system of the client, so it differs between platforms. A connection reset by the peer is `54` on macOS and `104` on Linux.
* The MariaDB client words the same error as `Lost connection to server at ...`.

For comparison, this is a connection that works, for a service with the host name `foobar.us-east1.aws.clickhouse.cloud`:

```bash theme={null}
mysql -h foobar.us-east1.aws.clickhouse.cloud -P 3306 -u mysql4foobar --password
```

## Is the MySQL interface enabled?

The MySQL interface is off until you enable it for the service. In the ClickHouse Cloud console, open **Connect**, choose `MySQL` in the **Connect with** list, and turn on the switch. This exposes port `3306` for the service, and the dialog shows the MySQL user name to use. See [Enabling the MySQL interface on ClickHouse Cloud](https://clickhouse.com/docs/concepts/features/connect-to-clickhouse/protocols/compatibility/mysql.md#enabling-the-mysql-interface-on-clickhouse-cloud).

## Does the user name have the `mysql4` prefix?

Every service has a built-in user `mysql4<subdomain>` with the same password as the `default` user, where `<subdomain>` is the first part of the host name of the service. Additional users for the MySQL interface are named `mysql4<subdomain>_<name>`. For the host name above, these are `mysql4foobar` and, for example, `mysql4foobar_team1`.

The prefix tells ClickHouse Cloud which service a connection belongs to when the client does not send SNI information in its TLS handshake, and the `mysql` console client is such a client. A user name that does not follow this format leads to the error above, even if the same user works with `clickhouse-client`. See [Creating multiple MySQL users in ClickHouse Cloud](https://clickhouse.com/docs/concepts/features/connect-to-clickhouse/protocols/compatibility/mysql.md#creating-multiple-mysql-users-in-clickhouse-cloud).

## Is your IP address in the IP access list?

The [IP access list](https://clickhouse.com/docs/products/cloud/guides/security/connectivity/setting-ip-filters.md) of the service filters the connections of the MySQL interface too. A connection from an address that is not on the list is closed.

To check from the machine that runs the MySQL client, use the test from the IP access list page:

```bash theme={null}
curl https://foobar.us-east1.aws.clickhouse.cloud:8443
```

It prints `Ok.` if the address is allowed, and a connection reset error if it is not. Add the public address of the client to the list. For a hosted BI tool, add the addresses that its vendor publishes.

## Is the password stored as `double_sha1_password`?

The password of a user of the MySQL interface must be in double SHA1 format. With another type, for example `sha256_password`, the same user and password work in `clickhouse-client`, but the MySQL client fails, typically one step later in the handshake:

```text theme={null}
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading final connect information', system error: 0
```

Check how the password is stored:

```sql theme={null}
SELECT name, auth_type
FROM system.users
WHERE name LIKE 'mysql4%';
```

```text theme={null}
   ┌─name───────────────┬─auth_type───────────┐
1. │ mysql4foobar_team1 │ ['sha256_password'] │
   └────────────────────┴─────────────────────┘
```

Set the password again with the right type. Replace `<password>` with a password of your own:

```sql theme={null}
ALTER USER mysql4foobar_team1 IDENTIFIED WITH double_sha1_password BY '<password>';
```

`IDENTIFIED WITH` without `ADD` replaces all authentication methods of the user, see the examples for [`ALTER USER`](https://clickhouse.com/docs/reference/statements/alter/user#examples). After this statement, the user can sign in only with this password, on every interface. If other applications use the same user with a different password or authentication method, change them at the same time, or leave that user as it is and [create a separate user](https://clickhouse.com/docs/concepts/features/connect-to-clickhouse/protocols/compatibility/mysql.md#creating-multiple-mysql-users-in-clickhouse-cloud) for the MySQL interface.

## If the connection still fails

* Make sure that the service is running and that your network allows outgoing connections to port `3306`.
* Connect from the same machine with `clickhouse-client` or `curl` to find out whether the problem is specific to the MySQL interface.
* Contact [ClickHouse support](https://clickhouse.com/support/program).

## Related pages

* [MySQL interface](https://clickhouse.com/docs/concepts/features/connect-to-clickhouse/protocols/compatibility/mysql.md)
* [I am unable to access a ClickHouse Cloud service](https://clickhouse.com/docs/resources/support-center/knowledge-base/cloud-services/unable-to-access-cloud-service.md)
