

# Troubleshooting connection and sign-in problems

A connection to the routing endpoint of a database cluster group for Aurora runs through the following layers: the client to the routing endpoint (DNS, the VPC endpoint, TLS), the routing layer, the routing layer to the member cluster, and the member cluster itself. The error code tells you which layer to check first. A direct connection to a member cluster uses only the last layer. For the full text of each error, see [Error codes for database cluster groups for Aurora](databaseclustergroups-error-reference.md).

## Connecting fails, is slow, or drops
<a name="databaseclustergroups-connecting-fails-or-is-slow"></a>

**Symptom.** A client can't connect to the routing endpoint, connecting is slow, a connection drops, or a query stops responding and times out. For a sign-in without TLS, see [A sign-in without TLS fails](#databaseclustergroups-ts-connections-tls). For a refused sign-in, see [Sign-in is refused](#databaseclustergroups-authentication-errors-in-detail).

**Check, cause, and fix.** Find what the client reports in the following table.


| The client reports | Check (where it runs) | Cause | Fix | 
| --- | --- | --- | --- | 
| Aurora MySQL: 2003 or 2002, ECONNREFUSED or ETIMEDOUT on connect | Client host: the host, port, and DNS resolution | The network path: DNS from the client's VPC, the endpoint's security group, or a tunnel | Correct the network path. For more information, see [Network access](databaseclustergroups-network.md) | 
| A connection closes after it was idle or open for a long time. Aurora MySQL: 2013 Lost connection or 4031 on the next statement | Client: how long ago the connection opened, and when it last ran a statement | At its idle close after 30 minutes, the routing layer sends no error, and the next statement gets 2013. At the 12-hour maximum lifetime, a connection that is idle between statements first gets error 4031 (HY000), Connection closed: maximum connection lifetime reached. Older clients report 2013 instead ([Idle close and connection lifetime](databaseclustergroups-connection-management.md#databaseclustergroups-connection-management-idle-close)) | Reconnect and retry. Set the pool's idle timeout and maximum connection lifetime below the routing layer's limits. Don't make your retry logic depend on an error cause | 
| Aurora MySQL: every client gets 2013 or 4031 at the same moment | Each member cluster (direct): its recent error log entries on each instance endpoint (queries after this table) | When the Aborted connection entries of the burst start in the same millisecond on every member cluster, the routing layer closed idle connections together. No single member cluster is the cause | Add jitter to the pool's idle timeout and maximum connection lifetime | 
| Aurora MySQL: 2013 in the middle of a workload | AWS CLI: the member cluster's events. For more information, see [Working with Amazon RDS event notification](USER_Events.md). Each member cluster (direct): its recent error log entries (queries after this table) | A failover on the member cluster ended the connection. Work in an open transaction wasn't committed. A restart of the member cluster's writer, such as a reboot or a crash, ends every routed session that has a member cluster session there in the same way. So does a KILL of that member cluster session, or the member cluster's wait\_timeout or aurora\_transaction\_timeout | Reconnect, and run the whole transaction again. If routed statements then fail, see [A member cluster is unreachable through the routing endpoint](databaseclustergroups-ts-stalls.md#databaseclustergroups-a-member-cluster-is-unreachable-through-the-router). For a session timeout, bound the time that each transaction stays open in the application | 
| Aurora MySQL: 1193 Unknown system variable on routed statements after the session sets a variable | Client: the SET statements that the application or the driver sends, for example at connect | The session set a variable that the member cluster doesn't know. The routing layer replays the session's settings on each member cluster that the session reaches | Correct or remove the variable, and then open a new connection | 
| Getting a connection from the pool times out | Client: the pool's acquisition timeout | The routing layer doesn't queue clients, so the pool acquisition timeout comes from the application's own pool. When a member cluster can't open a session, the statement fails with error 1053 (08S01), and the connection closes. When the routing layer's wait for a member cluster connection runs out, the statement fails with error 9501 (HY000), and the connection stays open. Over the routing layer's connection limits, a new connection gets error 1040 | Set the acquisition timeout to the wait that your application accepts. After 1053 or 1040, reconnect and retry with backoff. After 9501, retry the statement. Check each member cluster's load and connection limit (next row) | 
| A query stops responding, then times out | Each member cluster (direct): connection counters and max\_connections (queries after this table) | The member cluster is slow, locked, or at its connection limit | Size and cap each pool against the max\_connections of every member cluster that it reaches. For more information, see [Managing connections](databaseclustergroups-connection-management.md) | 
| Aurora MySQL: connecting is slow rather than the statement | AWS CLI: AuroraSlowHandshakeCount and AuroraSlowConnectionHandleCount in CloudWatch for each member cluster's DBClusterIdentifier (command after this table) | These metrics are cumulative, so compare the change from one minute to the next. A rise on one member cluster only points at that member cluster | Investigate the member cluster whose counts rise. For a member cluster that stalls, see [Every client stalls or slows down](databaseclustergroups-ts-stalls.md#databaseclustergroups-every-client-stalls-or-slows-down) | 

```sql
-- Runs at: member cluster endpoint (direct).
SELECT @@max_connections AS max_connections,
       (SELECT COUNT(*) FROM performance_schema.threads WHERE TYPE = 'FOREGROUND') AS foreground_threads;
```

On each member cluster (direct), read the connection error counters. Rising `Aborted_connects` or `Connection_errors_%` values point at failed sign-ins on the member cluster. Rising `Aborted_clients` values point at clients that dropped their connections.

```sql
-- Runs at: member cluster endpoint (direct).
SHOW GLOBAL STATUS LIKE 'Aborted_%';
SHOW GLOBAL STATUS LIKE 'Connection_errors%';
```

To find a restart or a failure around the time of a `2013`, read the recent warnings and errors in the member cluster's error log on each instance (direct). The table holds recent entries since the last restart.

```sql
-- Runs at: instance endpoint of each member cluster instance (direct).
SELECT LOGGED, PRIO, ERROR_CODE, LEFT(DATA, 200) AS message
FROM performance_schema.error_log
WHERE PRIO IN ('Warning', 'Error')
ORDER BY LOGGED DESC LIMIT 50;
```

If every client gets `2013` at the same moment, run the preceding error log query on each instance endpoint of every member cluster. Compare the times of the `Aborted connection` entries of the burst.

If connecting is slow rather than the statement, read `AuroraSlowHandshakeCount` and `AuroraSlowConnectionHandleCount` in CloudWatch for each member cluster's `DBClusterIdentifier`. Run the following AWS CLI command once for each member cluster. These metrics are cumulative, so compare the change from one minute to the next. A rise on one member cluster only points at that member cluster.

```bash
aws cloudwatch get-metric-data --region {{REGION}} \
    --start-time {{START_TIME}} --end-time {{END_TIME}} \
    --metric-data-queries '[
      {"Id":"handshake","MetricStat":{"Metric":{"Namespace":"AWS/RDS","MetricName":"AuroraSlowHandshakeCount",
        "Dimensions":[{"Name":"DBClusterIdentifier","Value":"{{MEMBER_CLUSTER_ID}}"}]},"Period":60,"Stat":"Maximum"}},
      {"Id":"handle","MetricStat":{"Metric":{"Namespace":"AWS/RDS","MetricName":"AuroraSlowConnectionHandleCount",
        "Dimensions":[{"Name":"DBClusterIdentifier","Value":"{{MEMBER_CLUSTER_ID}}"}]},"Period":60,"Stat":"Maximum"}}
    ]'
```

On Aurora MySQL, the CloudWatch `DatabaseConnections` metric of a member cluster includes the sessions that the routing layer and data movement jobs open on it. For other connection errors that a member cluster also returns, see [Troubleshooting for Amazon Aurora](CHAP_Troubleshooting.md).

To connect a member cluster session that dropped or stopped responding back to its session at the routing endpoint, see [Tracing a session or statement across the group](databaseclustergroups-trace-session.md). For a connection that waits on a lock, or for every client at once, see [Troubleshooting an unreachable member cluster or a stall](databaseclustergroups-ts-stalls.md).

Sign-in doesn't open member cluster sessions. On Aurora MySQL, if the routing layer can't read the group's metadata for the router user during sign-in, the sign-in fails in one of two ways. The routing layer closes the connection with no error, which the client reports as `2013 Lost connection to MySQL server at 'reading authorization packet', system error: {{N}}`, or it sends error `1105` (HY000) `The router could not open a session for this connection` in place of the sign-in's OK and then closes the connection. Retry the connection with backoff. A member cluster session opens at the first statement that reaches that member cluster. If it doesn't open in time, that statement gets error `1053` (SQLSTATE `08S01`) `Member cluster session did not open in time; reconnect and retry the statement`, and the routing layer closes the connection. For the other errors at that point, see [Routing and data mapping errors](databaseclustergroups-errors-routing.md).

## A sign-in without TLS fails
<a name="databaseclustergroups-ts-connections-tls"></a>

**Symptom.** A connection or a sign-in that doesn't use TLS fails. **Check.** In the client, check the driver's TLS setting and the TLS versions that it offers. On Aurora MySQL, also read the router user's `require_ssl` and `authentication_method` in `router_user_definition` ([Sign-in is refused](#databaseclustergroups-authentication-errors-in-detail)).

**Cause.** Clients connect to the routing layer with TLS, and the routing layer connects to the member clusters with mutual TLS. The routing endpoint accepts only TLS 1.2 and TLS 1.3 and refuses a connection without TLS. On Aurora MySQL, the refused connection gets error `3159` after the credential and account-lock checks. A direct connection to a member cluster follows that member cluster's own TLS settings. For the settings and certificates, see [Encryption in transit (TLS) and at rest](databaseclustergroups-tls.md).

**Fix.** Connect with TLS, and don't retry without it.
+ A connection without TLS gets error `3159`.
+ A router user set to `REQUIRE SSL` gets error `1045` without TLS.
+ A `caching_sha2_password` router user gets client error `2061` when the sign-in needs a full authentication, for example the first sign-in after a password change or after the routing layer restarts.

Connect with TLS, for example with the `--ssl-mode=REQUIRED` option of the `mysql` client. For client TLS settings, see [TLS connections to Aurora MySQL DB clusters](AuroraMySQL.Security.md#AuroraMySQL.Security.SSL).

## Sign-in is refused
<a name="databaseclustergroups-authentication-errors-in-detail"></a>

**Symptom.** A sign-in at the routing endpoint is refused, the connection closes during sign-in, or the connection opens and its first statement is refused.

**Check.** At the routing endpoint, as a router user with `dbclustergroup_user_admin`, read the user name's host parts, authentication method, and lock state ([router\_user\_definition](databaseclustergroups-sysviews-router-user-definition.md)). Then find the message in the following table.

```sql
-- Runs at: routing endpoint.
SELECT username, host, authentication_method, require_ssl, account_locked
FROM dbclustergroup_sys.router_user_definition
WHERE username = '{{USER_NAME}}';
```

**Cause.** The routing layer checks authentication against the group's router users at connection time, before it opens any member cluster session. A failed sign-in never reaches a member cluster, and a member cluster user can't sign in at the routing endpoint. The member cluster that owns the data checks authorization at statement time, so a credential that connects can still be refused on its first statement. For more information, see [Router users and routing layer privileges](databaseclustergroups-router-users.md).

**Fix.** Find the case in the following table, or in the details that follow.


| You see | Cause | Fix | 
| --- | --- | --- | 
| The connection opens, and the first statement fails with a permission error | The member cluster that owns the data checks authorization. The member cluster user of the same name might not exist there, or might lack a grant | Create the member cluster user on that member cluster, and grant it the privileges it needs. Handle a permission failure where you handle statement errors | 
| The same credential succeeds on one member cluster and fails on another | Each member cluster answers for its own accounts and grants, and the group doesn't make a user name unique across member clusters | Read the account and its grants on the member cluster that refused the statement. Keep your naming scheme unique across member clusters | 
| A password change, a grant, or a revocation has no effect on a new connection | Authentication and authorization data is eventually consistent across the routing layer | Retry the step that depends on the change. There is no FLUSH PRIVILEGES statement that forces it | 
| The routing endpoint refuses new connections, and open sessions keep working | Part of the routing layer can't refresh its authentication data | Take no action. AWS manages the recovery, and open sessions aren't affected | 
| A member cluster user's credentials are refused at the routing endpoint | The routing endpoint signs in router users only. On Aurora MySQL, the routing endpoint refuses a user name with no matching router user, and doesn't fall back to the member cluster's own accounts | Create a router user with that name at the routing endpoint, or connect to the member cluster endpoint directly | 

Router users take `caching_sha2_password` (the default) or `mysql_native_password`. IAM database authentication for router users isn't available at preview (see [IAM database authentication](databaseclustergroups-iam.md#databaseclustergroups-iam-db-auth)). Most failed sign-ins return `1045`. The routing layer matches a host part against the client IP address and doesn't resolve host names. The routing layer applies `PASSWORD EXPIRE` at sign-in. A client that supports expired passwords signs in and must reset the password before it runs other statements; other clients get error `1862`. `REQUIRE` accepts only `NONE` and `SSL`. `FLUSH PRIVILEGES` isn't supported or needed.

In the following table, `<USER_NAME>` is the router user name and `<HOST>` is its host part. Run each fix at the routing endpoint.

The host in a `1045` message from the routing endpoint is your client's IP address. A client that sends no password can also get client error `2027` (Malformed packet). Configure it to send the router user's password.


| Message (code) | Cause | Fix | 
| --- | --- | --- | 
| <a name="databaseclustergroups-access-denied-for-user-user-name-host-using-password-yes"></a>Access denied for user '<USER\_NAME>'@'<HOST>' (using password: YES) (1045, SQLSTATE 28000) | No router user has this name, no host part matches the client IP address, the password is wrong, or the router user is set to REQUIRE SSL and the connection doesn't use TLS. An unsupported plugin returns Plugin '<PLUGIN\_NAME>' is not loaded (1524, SQLSTATE HY000) | First read the routing layer's error log entries for the sign-in ([Error log entries for failed sign-ins](#databaseclustergroups-router-error-log-entries)). Then create the router user, or add a host part that matches: an IP address, a CIDR range such as 10.0.0.0/16, an address and netmask, or a pattern such as 10.0.%. Reset the password or plugin with ALTER USER. Connect with TLS | 
| <a name="databaseclustergroups-access-denied-for-user-user-name-host-using-password-no"></a>Access denied for user '<USER\_NAME>'@'<HOST>' (using password: NO) (1045, SQLSTATE 28000) | The client sent no password | Configure the client to send the router user's password | 
| <a name="databaseclustergroups-access-denied-for-user-user-name-host-account-is-locked"></a>Access denied for user '<USER\_NAME>'@'<HOST>'. Account is locked. (3118, SQLSTATE HY000) | The credentials are correct, and the router user is locked. A wrong password for a locked router user returns 1045 | Confirm that nobody locked it on purpose, for example to remove access. Then run ALTER USER '<USER\_NAME>'@'<HOST>' ACCOUNT UNLOCK; as a router user with dbclustergroup\_user\_admin. New sign-ins read the lock state | 
| Your password has expired. To log in you must change it using a client that supports expired passwords. (1862) | The router user's password expired | From another session, as a router user with dbclustergroup\_user\_admin, reset the password with ALTER USER '<USER\_NAME>'@'<HOST>' IDENTIFIED BY '<NEW\_PASSWORD>'; | 
| Authentication plugin 'caching\_sha2\_password' cannot be loaded (2059, client) | The client is too old to support caching\_sha2\_password, the router user's plugin | Use a newer client. For a client that can't support caching\_sha2\_password, create the router user with mysql\_native\_password | 
| <a name="databaseclustergroups-lost-connection-to-mysql-server-at-reading-authorization-pac"></a>Lost connection to MySQL server at 'reading authorization packet', system error: {{N}} (2013, client) | The routing layer closed the sign-in with no error, because it couldn't read the router user, or because the client didn't finish the sign-in before a timeout. The routing layer writes no error log entry for these cases | Try again. If the error continues, contact AWS Support | 

The routing layer doesn't lock a router user after failed sign-ins.

The routing layer accepts `COM_CHANGE_USER`, for example the `mysql` client `\u` command or a driver's change-user call. It resets the session, as Aurora MySQL does, signs in the requested router user, and opens a new session with the database that the request names. If the routing layer can't reset the session or open the new one, the client gets error `1105` (SQLSTATE `HY000`), and the routing layer closes the connection. If the sign-in of the requested user fails, the client gets the sign-in errors in the preceding table.

### Error log entries for failed sign-ins
<a name="databaseclustergroups-router-error-log-entries"></a>

For most failed sign-ins, the routing layer writes an error log entry with more detail than the client's error. It writes none when it closes a sign-in without an error. On Aurora MySQL, the entries use the MySQL 8.0 error log format. Each part of the routing layer writes its own log stream, so search every log stream in the log group.


| Error log entry | Meaning | 
| --- | --- | 
| [MY-010926] [Router] Access denied for user '<USER\_NAME>'@'<CLIENT\_IP>' (using password: NO) | The client sent no password. | 
| [MY-010926] [Router] Access denied for user '<USER\_NAME>'@'<CLIENT\_IP>' (using password: YES) | The client sent a password, and the sign-in wasn't accepted. | 
| [MY-010914] [Router] Plugin '<PLUGIN\_NAME>' is not loaded | The router user uses an authentication plugin that the routing layer doesn't support. | 
| [MY-010927] [Router] Access denied for user '<USER\_NAME>'@'<CLIENT\_IP>'. Account is locked. | The credentials are correct, and the router user is locked. | 

## Fixing connection and sign-in errors by code
<a name="databaseclustergroups-ts-connections-error-fixes"></a>

The following table gives what to do for each connection and sign-in error, by its code and a short form of its message. For the message text and cause of each error, see [Connection and sign-in errors](databaseclustergroups-errors-connection.md).


| Aurora MySQL code (SQLSTATE) | Error | What to do | 
| --- | --- | --- | 
| 1045 (28000) | Aurora MySQL: Access denied for user '<USER\_NAME>'@'<HOST>' (using password: YES) | Do the step for the cause: create the router user at the routing endpoint, add a host part that matches the client IP address, reset the password, change the plugin to caching\_sha2\_password, or connect with TLS. See [Sign-in is refused](#databaseclustergroups-authentication-errors-in-detail). | 
| 1045 (28000) | Access denied for user '<USER\_NAME>'@'<HOST>' (using password: NO) | Configure the client to send the password of the router user. | 
| 3118 (HY000) | Access denied for user '<USER\_NAME>'@'<HOST>'. Account is locked. | Confirm that nobody locked the router user on purpose. Then, as a user with the dbclustergroup\_user\_admin privilege, run ALTER USER '<USER\_NAME>'@'<HOST>' ACCOUNT UNLOCK; at the routing endpoint. | 
| 2061 (client) | Authentication plugin 'caching\_sha2\_password' reported error: Authentication requires secure connection. | Connect with TLS. For client TLS settings, see [TLS connections to Aurora MySQL DB clusters](AuroraMySQL.Security.md#AuroraMySQL.Security.SSL). | 
| 2013 (client) | Lost connection to MySQL server at 'reading authorization packet', system error: {{N}} | Try again. If the error continues, contact AWS Support. See [Sign-in is refused](#databaseclustergroups-authentication-errors-in-detail). | 
| 3159 (HY000) | A connection without TLS | Connect with TLS, for example with the --ssl-mode=REQUIRED option of the mysql client. See [A sign-in without TLS fails](#databaseclustergroups-ts-connections-tls). | 
| 2013 (client) | Lost connection to MySQL server during query | Open a new connection, and run the whole transaction again. A write that was in progress might already be committed, so retry it only if it's safe to apply twice. See [Idle close and connection lifetime](databaseclustergroups-connection-management.md#databaseclustergroups-connection-management-idle-close) and [Retrying after an error](databaseclustergroups-queries.md#databaseclustergroups-queries-retries). | 
| 1227 (42000) | Access denied; you need the '<DBCLUSTERGROUP\_PRIVILEGE>' privilege for this operation | Grant the privilege for database cluster groups for Aurora to the router user. Grant data privileges, such as SELECT, to the member cluster user on each member cluster. See [Router users and routing layer privileges](databaseclustergroups-router-users.md). | 
| 1396 (HY000) | String '<value>' is too long for user name (should be no longer than 32), or String '<value>' is too long for host name (should be no longer than 255) | Use a shorter name. For the limits, see [Limitations and considerations for database cluster groups for Aurora](databaseclustergroups-limitations.md). | 