Pre-General Availability Draft: 2017-09-21
Several options are available to indicate whether to use encrypted connections, and to specify the appropriate certificate and key files. This section provides general guidance about configuring the server and clients for encrypted connections:
For a complete list of options related to establishment of encrypted connections, see Section 6.4.2, “Command Options for Encrypted Connections”. If you need to create the required certificate and key files, see Section 6.4.3, “Creating SSL and RSA Certificates and Keys”.
Encrypted connections can be used between master and slave replication servers. See Section 18.3.9, “Setting Up Replication to Use Encrypted Connections”.
Encrypted connections are available through the MySQL C API. See Section 27.7.18, “C API Encrypted Connection Support”.
On the server side, the
option specifies that the server permits but does not require
encrypted connections. This option is enabled by default.
These options on the server side identify the certificate and key files the server uses when permitting clients to establish encrypted connections:
For example, to enable the server for encrypted connections,
start it with these lines in the
file, changing the file names as necessary:
[mysqld] ssl-ca=ca.pem ssl-cert=server-cert.pem ssl-key=server-key.pem
Each option names a file in PEM format. If you need to create
the required certificate and key files, see
Section 6.4.3, “Creating SSL and RSA Certificates and Keys”. Alternatively, if you
have a MySQL source distribution, you can test your setup using
the demonstration certificate and key files in its
MySQL servers compiled using OpenSSL can generate missing certificate and key files automatically at startup. See Section 126.96.36.199, “Creating SSL and RSA Certificates and Keys using MySQL”.
The server performs certificate and key file autodiscovery. If
--ssl is enabled (possibly along
--ssl-cipher) and other
are not given to configure encrypted connections explicitly, the
server attempts to enable support for encrypted connections
automatically at startup:
If the server discovers valid certificate and key files named
server-key.pemin the data directory, it enables support for encrypted connections by clients. (The files need not have been generated automatically; what matters is that they have the indicated names and are valid.)
If the server does not find valid certificate and key files in the data directory, it continues executing but without support for encrypted connections.
If the server automatically enables support for encrypted connections, it writes a note to the error log. If the server discovers that the CA certificate is self-signed, it writes a warning to the error log. (The certificate is self-signed if created automatically by the server, or manually using mysql_ssl_rsa_setup.)
For further control over whether clients must connect using
encryption, use the
variable; see Section 5.1.5, “Server System Variables”. To
specify permitted encryption protocols explicitly, use the
tls_version system variable;
see Section 6.4.6, “Encrypted Connection Protocols and Ciphers”.
By default, MySQL client programs attempt to establish an
encrypted connection if the server supports encrypted
connections, with further control available through the
In the absence of an
--ssl-modeoption, clients attempt to connect using encryption, falling back to an unencrypted connection if an encrypted connection cannot be established. This is also the behavior with an explicit
--ssl-mode=REQUIRED, clients require an encrypted connection and fail if one cannot be established.
--ssl-mode=DISABLED, clients use an unencrypted connection.
For additional security, the following options on the client
side identify the certificate and key files clients use when
establishing encrypted connections to the server. They are
similar to the options used on the server side, but
--ssl-key identify the client
public and private key:
Depending on the encryption requirements of the MySQL account used by a client, the client may be required to specify certain options to connect using encryption to a MySQL server that supports encrypted connections.
Suppose that you want to connect using an account that has no
special encryption requirements or was created using a
CREATE USER statement that
REQUIRE SSL option. Assuming
that the server supports encrypted connections, a client can
connect using encryption with no
--ssl-mode option or with an
For an account with
REQUIRE SSL, the
connection attempt fails if an encrypted connection cannot be
established. For an account with no special encryption
requirements, the attempt falls back to an unencrypted
connection if an encrypted connection cannot be established. To
prevent fallback and fail if an encrypted connection cannot be
obtained, connect like this:
If the account has more stringent security requirements, other options must be specified to establish an encrypted connection:
For accounts with
REQUIRE X509, clients must specify at least
--ssl-key. In addition,
--ssl-cais recommended so that the public certificate provided by the server can be verified. For example:
mysql --ssl-ca=ca.pem \ --ssl-cert=client-cert.pem \ --ssl-key=client-key.pem
For accounts that have
REQUIRE SUBJECT, the option requirements are the same as for
REQUIRE X509, but the certificate must match the issue or subject, respectively, specified in the account definition.
For additional information about the
clause, see the discussion in Section 188.8.131.52, “CREATE USER Syntax”.
To prevent use of encryption and override other
invoke the client program with
To specify permitted encryption protocols explicitly, use the
--tls-version option; see
Section 6.4.6, “Encrypted Connection Protocols and Ciphers”.
To determine whether the current connection with the server uses
encryption, check the value of the
Ssl_cipher status variable. If
the value is empty, the connection is not encrypted. Otherwise,
the connection is encrypted and the value indicates the
encryption cipher. For example:
mysql> SHOW SESSION STATUS LIKE 'Ssl_cipher'; +---------------+---------------------------+ | Variable_name | Value | +---------------+---------------------------+ | Ssl_cipher | DHE-RSA-AES128-GCM-SHA256 | +---------------+---------------------------+
For the mysql client, an alternative is to
command and check the
mysql> \s ... SSL: Not in use ...
mysql> \s ... SSL: Cipher in use is DHE-RSA-AES128-GCM-SHA256 ...