How to enable SSL connection protection in MySQL
With the increasing importance of data security, many organizations and developers have begun to pay attention to how to enable SSL connection protection in database connections. SSL encryption protocol to protect data transmission. In a MySQL database, enabling SSL connections ensures that data is properly encrypted and authenticated during transmission. This article describes how to enable SSL connections in MySQL to protect your database and provides corresponding code examples.
Step one: Prepare SSL certificate and key
When enabling SSL connection, you need to prepare SSL certificate and key. Here are some basic preparation steps:
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server-key.pem -out server-cert.pem
This command will generate a self-signed SSL certificate and private key. Please make sure to keep these files securely.
$ sudo cp server-cert.pem /etc/mysql/ssl/ $ sudo cp server-key.pem /etc/mysql/ssl/
Please modify the corresponding directory according to your actual situation.
Step 2: Modify the MySQL configuration file
Next, you need to modify the MySQL configuration file to enable SSL connections.
$ sudo vi /etc/mysql/my.cnf
[mysqld] ssl-ca=/etc/mysql/ssl/server-cert.pem ssl-cert=/etc/mysql/ssl/server-cert.pem ssl-key=/etc/mysql/ssl/server-key.pem
These configuration items specify Path to SSL certificate and key. Please modify it according to your actual situation.
Step 3: Restart the MySQL service
After completing the above configuration, you need to restart the MySQL service to make the configuration take effect:
$ sudo systemctl restart mysql
Step 4: Test the SSL connection
Now, you can test whether the SSL connection is successful.
$ mysql -h localhost -u username -p
Please replace username
with your MySQL username.
mysql> SHOW STATUS LIKE 'Ssl_cipher';
If the returned result contains RSA
, it means that the SSL connection has been successfully enabled.
At this point, you have successfully enabled SSL connection in MySQL to protect the database.
Summary
Enabling SSL connections during data transfer is an effective way to ensure data security. This article describes how to enable SSL connections in MySQL and provides corresponding code examples. By following the steps above, you can enable SSL connections in your MySQL database to protect your data.
Note: The code examples in the article are for Linux-based MySQL configurations. For other operating systems, follow the guidelines for the appropriate platform.
The above is the detailed content of How to enable SSL connection protection database in MySQL. For more information, please follow other related articles on the PHP Chinese website!