Hi! 👋 We are doing a big documentation refresh. Help us improve — what's missing or could be better? Let us know! Simply send an email or start a conversation in Google Groups!

MySQL Authentication

ℹInfo

Note: Changes made to the configuration on this page must be explicitly loaded to the runtime to take effect. Please refer to the Admin Commands documentation for details on the LOAD and SAVE commands.

Overview

ProxySQL deeply understands the MySQL authentication handshake and acts as both a server (for frontend clients) and a client (for backend servers). This allows ProxySQL to support various authentication plugins and security standards.


Supported Methods

ProxySQL supports the following standard MySQL authentication plugins for both frontend and backend connections:

  • mysql_native_password: The traditional SHA1-based authentication (default for MySQL < 8.0).
  • caching_sha2_password: The modern SHA2-based authentication (default for MySQL >= 8.0).
  • mysql_clear_password: Used primarily for integrating with external systems like LDAP or ProxySQL’s built-in LDAP support.

Extra Frontend Methods

  • SPIFFE: Certificate-based, password-less authentication.
  • LDAP: Authentication against OpenLDAP or Active Directory.

Version Support Matrix

ProxySQL Versionmysql_native_passwordcaching_sha2_password
Pre-2.0.2Frontend & BackendNot Supported
Pre-2.6.0Frontend & BackendBackend Only (Frontend requires clear-text pass)
Post-2.6.0Frontend & BackendFrontend & Backend

Handshake Control

The variable mysql-default_authentication_plugin controls which plugin ProxySQL announces to the client in the Initial Handshake Packet. Setting this correctly can reduce round-trips and avoid “Auth Switch” overhead.

Example: Defaulting to modern SHA2

SET mysql-default_authentication_plugin = 'caching_sha2_password';
LOAD MYSQL VARIABLES TO RUNTIME;

Changing User with COM_CHANGE_USER

A client can switch to another user on an open connection, without reconnecting, by sending COM_CHANGE_USER. This is mysql_change_user() in the C API, and it is also how many connection pools reset a connection before reusing it. How ProxySQL handles it for clients using caching_sha2_password depends on the release.

Innovation v3.1.13+ and AI/MCP v4.0.13+

COM_CHANGE_USER authenticates the new user exactly as a new connection by that user would, over the same transport. It gets the same results and the same error messages.

When the client names caching_sha2_password, ProxySQL replies with an Auth Switch Request:

  • to caching_sha2_password, when ProxySQL announced caching_sha2_password at connect time (mysql-default_authentication_plugin = 'caching_sha2_password');
  • to mysql_native_password, when ProxySQL announced mysql_native_password.

Some clients send no password data in COM_CHANGE_USER and wait for the server to ask (libmysqlclient, MariaDB Connector/C). Others send a caching_sha2_password scramble right away (Connector/J, Connector/Python and others). Both kinds work. For the second kind, ProxySQL ignores the scramble and uses the Auth Switch, which costs one extra round trip.

The same rules as a new connection apply:

Password stored in mysql_usersWhat the change of user needs
Clear text, or a hash whose clear text ProxySQL has cached from an earlier loginNothing more: fast authentication works on any connection
mysql_native_password hash (*...) or caching_sha2_password hash ($A$...), clear text not cachedFull authentication: an SSL connection, or the RSA key exchange (the client must request the server’s public key)
Wrong passwordError 1045 Access denied
ℹNote

Behaviour change. With mysql-default_authentication_plugin = 'caching_sha2_password', a client changing to a user whose password is stored as a *... hash used to be switched to mysql_native_password and succeed even without SSL. It now goes through caching_sha2_password. On a connection with neither SSL nor the RSA key exchange, this fails unless the clear text is cached, just as a new connection by that user fails there.

These releases also fix two problems with compressed connections:

  • After a change of user that needed an Auth Switch, the next command no longer closes the connection.
  • A zstd-compressed login that needs an Auth Switch no longer loses the connection on the first query.

COM_CHANGE_USER is still rejected for SPIFFE sessions and for users authenticated through pass-through authentication.

Stable v3.0, and Innovation/AI-MCP up to v3.1.12 / v4.0.12

COM_CHANGE_USER from a caching_sha2_password client fails in these cases:

  • Clients that send the scramble with COM_CHANGE_USER (Connector/J, Connector/Python and others): the change always fails with Access denied, even with the correct password.
  • Clients that send no password data (libmysqlclient, MariaDB Connector/C): ProxySQL switches the client to mysql_native_password. This works when the new user’s password is stored as clear text or as a *... hash, and fails when it is stored as a $A$... hash.
  • Compressed connections: after a change of user that needed an Auth Switch, the next command closes the connection.
  • zstd: a zstd-compressed login that needs an Auth Switch loses the connection on the first query.

To avoid these on these releases:

  • Reconnect instead of changing user. In a connection pool, turn off reset-by-change-user.
  • Or store the passwords of the users involved as clear text or *... hashes, and use a client that sends no password data with COM_CHANGE_USER.

Security Considerations

SSL Requirement

When using caching_sha2_password with hashed passwords, an SSL connection is strictly required between the client and ProxySQL to protect the challenge-response exchange.

Password Hashing

While ProxySQL can store clear-text passwords, it is highly recommended to use hashed passwords in production. See MySQL Password Management for details on generating hashes.


Apply your changes: Remember to use the appropriate LOAD and SAVE commands to activate and persist your authentication configuration. See the complete Admin Commands reference.