ssl-guides 2026-12-02 ⏱ 3 min read

Configure SSL for MySQL

Configure SSL for MySQL

MySQL SSL is opt-in per server, per user and per client. Prepare the certificates, require TLS on the accounts that need it, then check the session is really encrypted.

Step 1: Prepare certificates

You need a CA certificate, a server certificate and a server key. For a database with a public DNS name you can use a public CA certificate; Certbot can issue one. For internal names, create a private CA and sign the server certificate yourself, then give clients the CA file. The server certificate name must match the hostname clients use.

MySQL SSL, step 2: configure the server

[mysqld]
ssl_ca   = /etc/mysql/ssl/ca.pem
ssl_cert = /etc/mysql/ssl/server-cert.pem
ssl_key  = /etc/mysql/ssl/server-key.pem
tls_version = TLSv1.2,TLSv1.3
require_secure_transport = ON

require_secure_transport = ON makes the server refuse any TCP connection that is not encrypted. Unix socket connections are exempt because they never leave the machine. This setting exists in MySQL 5.7.8 and later; MariaDB uses different options, so check its documentation. The key file must be readable by the mysql user and no one else. Restart the service after editing.

MySQL SSL, step 3: require TLS per user

If you cannot enforce it globally yet, enforce it per account:

ALTER USER 'app'@'10.%' REQUIRE SSL;

-- stronger: require a valid client certificate
ALTER USER 'batch'@'10.%' REQUIRE X509;

REQUIRE SSL demands an encrypted connection. REQUIRE X509 also demands a client certificate signed by the CA. This is a good fit for service accounts, and it follows the same idea as Configure mTLS for APIs: Client Certificates.

Step 4: Connect from clients

--ssl-modeMeaning
DISABLEDNo encryption
PREFERREDEncrypt if possible, fall back silently
REQUIREDEncrypt, do not verify the server
VERIFY_CAEncrypt and check the CA
VERIFY_IDENTITYEncrypt, check the CA and the hostname
mysql -h db.example.com -u app -p \
  --ssl-mode=VERIFY_IDENTITY \
  --ssl-ca=/etc/mysql/ssl/ca.pem

VERIFY_IDENTITY is the setting that stops impersonation. Application drivers have their own equivalents, often called sslmode, useSSL or verifyServerCertificate; check your driver. Do not set the "trust all certificates" options that some tutorials suggest.

Step 5: Confirm encryption

SHOW SESSION STATUS LIKE 'Ssl_cipher';
SHOW GLOBAL VARIABLES LIKE '%ssl%';
SHOW GLOBAL VARIABLES LIKE 'tls_version';

A non-empty Ssl_cipher means the current session is encrypted. You can also look at the certificate the server presents using OpenSSL with -starttls mysql; the OpenSSL testing guide covers reading the output.

Renewing without a restart

MySQL 8.0.16 and later can reload certificate files at runtime with ALTER INSTANCE RELOAD TLS;, so a renewal does not need a restart. On other versions or on MariaDB, check whether a reload or restart is required. Wire this into a deploy hook; see automating renewal with Certbot. Public CA certificates expire in months, so private CA certificates with long lifetimes are common for databases, but then you own the expiry tracking.

Replication and managed services

Replicas connect as clients, so configure them with SOURCE_SSL=1 and the CA path (older versions use MASTER_SSL). Managed MySQL services usually enable TLS and provide a CA bundle; read the provider's current docs for the exact steps and for whether encryption is enforced. Protect the server key as described in how to protect SSL private keys.

Common mistakes

  • Relying on the auto-generated self-signed certificate and never verifying it.
  • Setting require_secure_transport before every client supports TLS, which locks out old applications. Roll it out per user first.
  • Using the hostname localhost or an IP in the client while the certificate carries a different name.
  • Copying the key with permissions that let other users read it.

Related reading: SSL for Python Flask, SSL for SMTP and SSL in Kubernetes.

Frequently Asked Questions

Is my MySQL connection already encrypted?

Maybe. MySQL 8.0 generates a self-signed certificate on first start, so the connection can be encrypted while nobody checks the server identity. Run SHOW STATUS LIKE 'Ssl_cipher' to see the session.

Do I need a public CA certificate for MySQL?

Only when clients connect over a public name. For internal names, a private CA you run is the usual choice.

Does renewal need a restart?

MySQL 8.0.16 and later can reload certificates with ALTER INSTANCE RELOAD TLS. Older versions and MariaDB may need a restart.

🔒 Test Your Website SSL Certificate Now
Run Free SSL Check →

✅ Post-Installation Verification & SEO Checklist

After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:

  • Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
  • Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
  • Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
  • Confirm both root and www versions resolve cleanly to one canonical HTTPS URL.
  • Verify your HTTPS property and sitemap.xml inside Google Search Console and Bing Webmaster Tools.
Technically Reviewed by TryFreeSSL Security Team
Last updated: 2026-12-05
About Us →

Free SSL Certificates, Live SSL Checker & CSR Generator

Issue trusted Let's Encrypt SSL certificates in 60 seconds with zero server setup.

Related Articles

🤖 TryFreeSSL AI Assistant