Combining Root CA, Client Certificate and Private Key into a Single File

Abstract: Resolve MySQL mutual TLS handshake failures caused by incorrectly combining the client certificate, private key, and CA bundle into a single file.

Created: 2026-08-23 by

MySQL requires separate files for the client certificate, private key, and CA bundle to enforce mutual TLS correctly. Combining them into a single file often causes handshake failures because the server cannot distinguish between the identity credentials and the trust anchors. This guide details the proper file structure and configuration steps.

The Correct File Structure

To establish a secure connection using mutual TLS (mTLS), you must provide three distinct components. The server needs to verify the client's identity against its own certificate store, while the client needs to verify the server's identity against a trusted Certificate Authority. Mixing these roles in one file breaks the cryptographic chain of trust validation logic inherent in OpenSSL and MySQL's SSL implementation. You should maintain the following directory structure on your client machine:
  • client-cert.pem: Your specific client certificate issued by the CA.
  • client-key.pem: The private key corresponding to client-cert.pem. This file must be protected with strict permissions (chmod 600).
  • ca-bundle.pem: The Root CA certificate or a concatenated file of all intermediate and root CAs that signed the server certificate.
This separation ensures that when the MySQL client initiates a connection, it presents its unique identity (cert and key) while trusting the authority defined in ca-bundle. If you combine the client key with the CA, the client might attempt to use the CA's private key for authentication, which is either impossible if you do not possess it, or a severe security vulnerability if you do.

Generating and Preparing the Certificates

Before configuring MySQL, ensure your certificates are generated correctly. You typically need a Certificate Authority (CA) to sign both the server and client certificates. If you are using a commercial CA, you will receive these files directly. If you are using self-signed certificates for development or internal networks, you can generate them using OpenSSL. First, generate the CA private key and certificate:
openssl genrsa -out ca-key.pem 2048
openssl req -new -x509 -key ca-key.pem -out ca-cert.pem -days 3650
Next, generate the client key and certificate request:
openssl genrsa -out client-key.pem 2048
openssl req -new -key client-key.pem -out client-req.pem
openssl x509 -req -in client-req.pem -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -out client-cert.pem -days 3650
Verify that client-cert.pem was indeed signed by ca-cert.pem using the following command:
openssl verify -CAfile ca-cert.pem client-cert.pem
If this returns "OK", your certificate chain is valid. Do not concatenate client-key.pem into client-cert.pem or ca-cert.pem. Keep them as separate files.

Configuring the MySQL Client

When connecting to the MySQL server, you must specify the paths to these three separate files. You can do this via the command line, a configuration file, or your application's connection string. Using the command line interface, the syntax is:
mysql --ssl-ca=ca-bundle.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem -u username -p
If you prefer using a configuration file such as ~/.my.cnf, add the following section under [client]:
[client]
ssl-ca=/path/to/ca-bundle.pem
ssl-cert=/path/to/client-cert.pem
ssl-key=/path/to/client-key.pem
Ensure that the file permissions on client-key.pem are set to 600 so that only the owner can read it. MySQL may refuse to start or connect if the private key file is readable by other users, citing a security risk. For applications connecting via libraries like JDBC, ODBC, or Python's mysql-connector, you must map these parameters accordingly. For example, in a JDBC URL, you would include:
jdbc:mysql://host:3306/db?ssl=true&sslCaLocation=/path/to/ca-bundle.pem&sslCertLocation=/path/to/client-cert.pem&sslKeyLocation=/path/to/client-key.pem
Always test the connection after configuration. A successful connection indicates that the client successfully authenticated using the provided certificate and verified the server's certificate against the CA bundle.

Troubleshooting Common Errors

If you encounter errors during connection, check the following common issues: 1. Certificate Mismatch: Ensure that the client-cert.pem matches the client-key.pem. You can check the modulus of both files:
openssl x509 -noout -modulus -in client-cert.pem | openssl md5
   openssl rsa -noout -modulus -in client-key.pem | openssl md5
These hashes must be identical. 2. Expired Certificates: Verify that neither the client certificate nor the CA certificate has expired. Use openssl x509 -enddate -noout -in client-cert.pem to check the expiration date. 3. Permission Denied: If MySQL reports permission issues, run chmod 600 client-key.pem. On Windows, ensure the user account running the MySQL client has read access to the certificate files. 4. Server Configuration: Remember that the server also needs its own certificate and key configured. If the server is not properly configured to request client certificates, the client's presentation of a certificate may be ignored or cause a handshake failure depending on the require_secure_transport setting. By maintaining separate files for the CA, client certificate, and private key, you adhere to standard TLS practices and ensure reliable connectivity with MySQL servers. This approach avoids the pitfalls of bundle confusion and provides a clear audit trail for each component of the secure channel. For more information on ensuring your MySQL service remains stable and secure, consider reviewing how to manage service startup and security updates. See Ensuring MySQL Service Starts with systemd and Long Homebrew MySQL @ 8.0 Gets Security Updates for related operational guidance.

Frequently Asked Questions

Can I combine the client cert and key into one PEM file?

Yes, you can combine the client certificate and private key into a single PEM file, but you must keep the CA bundle separate. Many tools accept a combined cert+key file for the --ssl-cert parameter, but the --ssl-ca must still point to the CA certificate file alone. Never mix the CA certificate into the client credential file.

Why does MySQL reject my combined file with an unsupported key error?

MySQL expects the --ssl-cert parameter to contain the client's public certificate and optionally its private key, but not the CA's certificate. If you include the CA certificate in the same file, the parser may fail to identify the correct certificate type for authentication. Splitting the files resolves this parsing ambiguity.

How do I verify the server's certificate against my CA bundle?

You can verify the server's certificate manually using OpenSSL before connecting. Run openssl s_client -connect host:port -CAfile ca-bundle.pem. If the verification returns "verify return code: 0 (ok)", your CA bundle correctly trusts the server's certificate. This step helps isolate whether connection issues are due to client credentials or server trust.

Is it safe to share the CA bundle file?

Yes, the CA bundle contains only public certificates and can be shared freely. It is used to verify the identity of the server, not to authenticate the client. Unlike the private key, which must remain secret, the CA certificate is part of the public trust infrastructure and poses no security risk if exposed.

What happens if I use the wrong CA bundle?

If you use an incorrect CA bundle, the client will fail to verify the server's certificate, resulting in a "certificate verify failed" error. This prevents man-in-the-middle attacks by ensuring you are connecting to the intended server. Always ensure the CA bundle matches the issuer of the server's certificate.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More