Databases 6 min read

Secure MySQL 8 with SSL: Step-by-Step Guide to Encrypt Your Data

Learn how to secure MySQL 8 connections by enabling SSL, covering the protocol’s encryption and authentication principles, generating certificates, configuring server and client settings, and testing the encrypted connection with detailed commands and practical examples.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Secure MySQL 8 with SSL: Step-by-Step Guide to Encrypt Your Data

1. SSL Principle

SSL (Secure Sockets Layer) is an encryption protocol used to securely transmit data. In MySQL it can encrypt communication between client and server, preventing eavesdropping and tampering. SSL provides encryption and authentication by combining asymmetric and symmetric encryption and using digital certificates.

Encrypted communication : SSL uses asymmetric encryption to exchange a symmetric session key, which is then used for data encryption.

Authentication : The server presents a digital certificate signed by a trusted CA; the client verifies it during the handshake.

Data encryption : After the handshake, both sides use the symmetric key to encrypt and decrypt traffic.

2. SSL Configuration and Practice

Steps to enable SSL in MySQL 8:

Step 1: Generate SSL certificate and private key

Use OpenSSL to create a self‑signed certificate and key:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server-key.pem -out server-cert.pem

This creates server-cert.pem and server-key.pem.

Step 2: Copy certificates to the MySQL server

Place the generated files in MySQL’s secure directory, typically the ssl subdirectory under the data directory.

Step 3: Configure MySQL to use SSL

Edit my.cnf (or my.ini) and add:

[mysqld]
ssl-ca=ssl/server-cert.pem
ssl-cert=ssl/server-cert.pem
ssl-key=ssl/server-key.pem

Ensure the paths match the actual locations of the certificate and key files.

Step 4: Restart MySQL

Save the configuration and restart the server to apply the changes.

Step 5: Configure a MySQL user to require SSL

Connect to MySQL and run:

ALTER USER '<username>'@'localhost' REQUIRE SSL;

Replace <username> with the real user name.

Step 6: Test the SSL connection

Connect using the CA certificate:

mysql -u <username> -p --ssl-ca=ssl/server-cert.pem

After a successful connection, run queries to verify that the session is encrypted.

Conclusion

Enabling SSL in MySQL 8 ensures encrypted data transmission and secure connections. By following the steps above, you can successfully configure and use SSL for MySQL.

SSL configuration diagram
SSL configuration diagram
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ConfigurationmysqlencryptionDatabase SecuritySSL
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.