MySQL 8.4 : SSL/TLS Setting2025/01/31 |
Configure SSL/TLS Setting on MySQL. |
|
[1] | On MySQL server side, mysqld generates self signed certificates by default, so it's possible to connect to mysqld with SSL/TLS session by default. |
# mysqld generates them [root@www ~]# ll /var/lib/mysql/*.pem -rw-------. 1 mysql mysql 1705 Jan 31 10:38 /var/lib/mysql/ca-key.pem -rw-r--r--. 1 mysql mysql 1108 Jan 31 10:38 /var/lib/mysql/ca.pem -rw-r--r--. 1 mysql mysql 1108 Jan 31 10:38 /var/lib/mysql/client-cert.pem -rw-------. 1 mysql mysql 1705 Jan 31 10:38 /var/lib/mysql/client-key.pem -rw-------. 1 mysql mysql 1705 Jan 31 10:38 /var/lib/mysql/private_key.pem -rw-r--r--. 1 mysql mysql 452 Jan 31 10:38 /var/lib/mysql/public_key.pem -rw-r--r--. 1 mysql mysql 1108 Jan 31 10:38 /var/lib/mysql/server-cert.pem -rw-------. 1 mysql mysql 1705 Jan 31 10:38 /var/lib/mysql/server-key.pem[root@www ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.4.2 Source distribution Copyright (c) 2000, 2024, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # SSL is enabled mysql> show variables like '%ssl%'; +-------------------------------------+-----------------+ | Variable_name | Value | +-------------------------------------+-----------------+ | admin_ssl_ca | | | admin_ssl_capath | | | admin_ssl_cert | | | admin_ssl_cipher | | | admin_ssl_crl | | | admin_ssl_crlpath | | | admin_ssl_key | | | mysqlx_ssl_ca | | | mysqlx_ssl_capath | | | mysqlx_ssl_cert | | | mysqlx_ssl_cipher | | | mysqlx_ssl_crl | | | mysqlx_ssl_crlpath | | | mysqlx_ssl_key | | | performance_schema_show_processlist | OFF | | ssl_ca | ca.pem | | ssl_capath | | | ssl_cert | server-cert.pem | | ssl_cipher | | | ssl_crl | | | ssl_crlpath | | | ssl_fips_mode | OFF | | ssl_key | server-key.pem | | ssl_session_cache_mode | ON | | ssl_session_cache_timeout | 300 | +-------------------------------------+-----------------+ 25 rows in set (0.01 sec) # certificates mysqld generated are 10 years available mysql> show status like 'Ssl_server_not%'; +-----------------------+--------------------------+ | Variable_name | Value | +-----------------------+--------------------------+ | Ssl_server_not_after | Jan 29 01:38:24 2035 GMT | | Ssl_server_not_before | Jan 31 01:38:24 2025 GMT | +-----------------------+--------------------------+ 2 rows in set (0.00 sec) |
[2] | To force require users to connect with SSL/TLS, set like follows. |
[root@www ~]# mysql Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.4.2 Source distribution Copyright (c) 2000, 2024, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # create a user who is required SSL/TLS mysql> create user redhat identified by 'password' require ssl; Query OK, 0 rows affected (0.01 sec) # show status SSL/TLS required users set [ssl_type] [ANY] mysql> select user,host,ssl_type,plugin from mysql.user; +------------------+-----------+----------+-----------------------+ | user | host | ssl_type | plugin | +------------------+-----------+----------+-----------------------+ | cent | % | | caching_sha2_password | | fedora | % | | caching_sha2_password | | redhat | % | ANY | caching_sha2_password | | mysql.infoschema | localhost | | caching_sha2_password | | mysql.session | localhost | | caching_sha2_password | | mysql.sys | localhost | | caching_sha2_password | | root | localhost | | caching_sha2_password | +------------------+-----------+----------+-----------------------+ 7 rows in set (0.00 sec) # set SSL/TLS required to an existing user mysql> alter user 'fedora'@'%' require ssl; Query OK, 0 rows affected (0.01 sec) mysql> select user,host,ssl_type,plugin from mysql.user; +------------------+-----------+----------+-----------------------+ | user | host | ssl_type | plugin | +------------------+-----------+----------+-----------------------+ | cent | % | | caching_sha2_password | | fedora | % | ANY | caching_sha2_password | | redhat | % | ANY | caching_sha2_password | | mysql.infoschema | localhost | | caching_sha2_password | | mysql.session | localhost | | caching_sha2_password | | mysql.sys | localhost | | caching_sha2_password | | root | localhost | | caching_sha2_password | +------------------+-----------+----------+-----------------------+ 7 rows in set (0.00 sec) |
[3] | To connect via TCP, SSL/TLS is enabled automatically. |
[root@www ~]# mysql -u cent -p --protocol=tcp Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 8.4.2 Source distribution Copyright (c) 2000, 2024, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # show status mysql> show status like 'ssl_cipher'; +---------------+------------------------+ | Variable_name | Value | +---------------+------------------------+ | Ssl_cipher | TLS_AES_128_GCM_SHA256 | +---------------+------------------------+ 1 row in set (0.00 sec) mysql> exit Bye |
Sponsored Link |
|