Skip to main content

How to Check When a MySQL Server Certificate Expires

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

When a MySQL server's certificate runs out, the clients that check it stop connecting, and the ones that don't carry on. So it's worth knowing the date before that day comes. MySQL will tell you, from any session.

Step 1: Ask MySQL​

Any account can run this:

mysql>
SHOW GLOBAL STATUS LIKE 'Ssl_server_not%';
Output
+-----------------------+--------------------------+
| Variable_name | Value |
+-----------------------+--------------------------+
| Ssl_server_not_after | Feb 8 06:18:35 2029 GMT |
| Ssl_server_not_before | Nov 6 06:18:35 2026 GMT |
+-----------------------+--------------------------+
2 rows in set (0.001 sec)

The mysql client showing Ssl_server_not_after and Ssl_server_not_before, the dates between which the server's certificate is valid.

This is the certificate MySQL has loaded, which is what clients get. If someone has replaced the file without reloading it, this still shows the old one.

Step 2: Read the File​

To see what a restart or a reload would give you:

Terminal
docker compose exec mysql openssl x509 -in /var/lib/mysql/server-cert.pem -noout -enddate
Output
notAfter=Feb 8 06:18:35 2029 GMT

If that date differs from Ssl_server_not_after, MySQL needs a reload.

Step 3: Check It from a Script​

-checkend takes a number of seconds, and sets its exit code. 2,592,000 is 30 days:

Terminal
docker compose exec mysql openssl x509 -in /var/lib/mysql/server-cert.pem -noout -checkend 2592000
Output
Certificate will not expire

It says Certificate will expire and exits with 1 when the date falls within that time, including one that has already gone. So a monitoring job only needs to look at the exit code.

How Long They Last​

Where the certificate came fromHow long it lasts
MySQL's automatic oneTen years, as the manual says
One you madeWhatever you put in -days
A managed serverYour provider's schedule, so watch for their notices

Common Mistakes​

MistakeWhat happensDo this instead
Assuming a client would tell youSslMode=Required connects to an expired certificate with no complaintCheck the date yourself
Reading only the fileMySQL may still be using an older oneCompare with Ssl_server_not_after
Checking the CA and not the server's certificateThey end on different datesCheck both

Troubleshooting​

SymptomLikely causeFix
Both values are emptyThe server has no working TLS right nowThe fix
certificate expired on, from a clientIt has passedThe fix
MY-015011 … certificate has expired in the logMySQL noticed at startupThe fix

Conclusion​

SHOW GLOBAL STATUS LIKE 'Ssl_server_not%' gives the dates of the certificate in use, from any session. Put openssl x509 -checkend in a monitoring job, so you hear about it weeks ahead.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.