Home Database Mysql Tutorial How to view and manage SSL connections in MySQL

How to view and manage SSL connections in MySQL

Sep 10, 2023 pm 05:22 PM
mysql manage ssl connection

如何在 MySQL 中查看和管理 SSL 连接

How to view and manage SSL connections in MySQL

SSL (Secure Sockets Layer) is a commonly used network communication protocol used between clients and servers. Establish a secure encrypted connection between them. In a database server, using SSL connections protects the transmission of sensitive data from being stolen or tampered with. MySQL also supports SSL connections and provides tools and commands to view and manage SSL connections.

  1. Check whether MySQL supports SSL connection
    Before using SSL connection, first make sure that the MySQL server has enabled the SSL function. You can view it in the MySQL client by executing the following command:
SHOW VARIABLES LIKE 'have_ssl';
Copy after login

If the result is 'YES', it means that MySQL supports SSL connections; if the result is 'DISABLED', it means that the SSL function is disabled; if The result is 'NO', which means MySQL is not installed or does not support SSL.

  1. Generate SSL certificate and private key
    To use SSL connection, you need to generate an SSL certificate and private key. Can be generated using OpenSSL tools. Here are the steps to generate a certificate and private key:
  • Open a command line terminal.
  • Enter the directory where the certificate and private key are stored.
  • Execute the following command to generate the private key file:
openssl genrsa -out private_key.pem 2048
Copy after login
  • Execute the following command to generate the certificate request file:
openssl req -new -key private_key.pem -out certificate_request.csr
Copy after login
  • Enter relevant information according to the prompts, such as country/region, province/city, organization name, unit name, etc.
  • Execute the following command to generate a self-signed certificate file:
openssl x509 -req -in certificate_request.csr -out certificate.pem -signkey private_key.pem -days 3650
Copy after login
  • Now, you have generated the SSL certificate file certificate.pem and the private key file private_key.pem.
  1. Configure MySQL server to use SSL connection
    To enable SSL connection on MySQL server, the following configuration is required:
  • Open MySQL The server's configuration file (usually my.cnf or my.ini).
  • Add the following configuration items in the [mysqld] section:
ssl-ca=/path/to/certificate.pem
ssl-cert=/path/to/certificate.pem
ssl-key=/path/to/private_key.pem
Copy after login

Replace "/path/to/" with the path to the actual certificate and private key files.

  • Save the configuration file and restart the MySQL server.
  1. View and manage SSL connections
    Once the MySQL server has enabled an SSL connection, you can use the following commands to view and manage the SSL connection:
  • Check whether the current connection uses SSL:
SHOW STATUS LIKE 'Ssl_cipher';
Copy after login
  • View the SSL certificate information of the current connection:
SHOW STATUS LIKE 'Ssl_cert';
Copy after login
  • View the SSL certificate issuance of the current connection Organization:
SHOW STATUS LIKE 'Ssl_ca';
Copy after login
  • View the number of SSL connections established on the server side:
SHOW STATUS LIKE 'Ssl_sessions_reused';
Copy after login
  • Close SSL connection:
SET GLOBAL ssl_cipher='';
Copy after login
  • Prompt the client to use SSL connection:
GRANT ALL ON database.* TO 'username'@'%' REQUIRE SSL;
Copy after login

Replace "database" with the name of the database to be authorized and "username" with the user name to be authorized.

Summary
Using SSL connections can increase the security of data transmission between the database server and the client. SSL connections can be easily enabled and managed by properly configuring your MySQL server and SSL certificate. Through the above steps, you can view and manage SSL connections in MySQL.

1500 words

The above is the detailed content of How to view and manage SSL connections in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

PHP's big data structure processing skills

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

How to optimize MySQL query performance in PHP?

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

How to use MySQL backup and restore in PHP?

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into a MySQL table using PHP?

What are the application scenarios of Java enumeration types in databases? What are the application scenarios of Java enumeration types in databases? May 05, 2024 am 09:06 AM

What are the application scenarios of Java enumeration types in databases?

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

How to use MySQL stored procedures in PHP?

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

How to create a MySQL table using PHP?

See all articles