Common SQL Errors

MySQL Error 65: EE_PUBLIC_KEY_NOT_IN_PEM_FORMAT - What It Means, Causes, and Fixes

Galaxy Team
August 5, 2025

MySQL throws EE_PUBLIC_KEY_NOT_IN_PEM_FORMAT when the given RSA public key is not in valid PEM encoding.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL Error 65: EE_PUBLIC_KEY_NOT_IN_PEM_FORMAT?

MySQL Error 65: EE_PUBLIC_KEY_NOT_IN_PEM_FORMAT signals that the RSA public key supplied to the client or server is not PEM-encoded. Convert the key to standard PEM (base64 text between -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY-----) or regenerate the key pair in PEM format to resolve the issue.

Error Highlights

Typical Error Message

Public key is not in Privacy Enhanced Mail format: '%s'. EE_PUBLIC_KEY_NOT_IN_PEM_FORMAT was added in 8.0.13.

Error Type

Connection Error

Language

MySQL

Symbol

EE_PUBLIC_KEY_NOT_IN_PEM_FORMAT

Error Code

65

SQL State

Explanation

Table of Contents

What does MySQL Error 65: EE_PUBLIC_KEY_NOT_IN_PEM_FORMAT mean?

MySQL 8.0.13 introduced RSA key-pair authentication for secure password exchange. When the server or client receives a public key that is not wrapped in standard Privacy Enhanced Mail boundaries, it raises EE_PUBLIC_KEY_NOT_IN_PEM_FORMAT.

The error halts connection establishment because MySQL cannot parse or validate a malformed key.

Fixing it quickly restores secure connectivity and avoids falling back to weaker authentication plugins.

What causes this error?

Most connections break because the key file was saved in DER or SSH format rather than base64-encoded PEM.

Manual copy-paste often drops the BEGIN and END lines, corrupting the header.

Upgrading to MySQL 8.0+ without regenerating keys, using wrong file paths, or feeding the server a client certificate instead of its public key also triggers the condition.

How do I fix MySQL Error 65: EE_PUBLIC_KEY_NOT_IN_PEM_FORMAT?

Verify the key first. A valid PEM file starts with -----BEGIN PUBLIC KEY----- and ends with -----END PUBLIC KEY-----.

If those markers are missing, convert or regenerate the key using openssl.

After conversion, update caching_sha2_password_public_key_path on the server or pass --ssl-public-key on the client. Restart the MySQL service or reconnect to confirm the error is gone.

Common scenarios and solutions

Database migrations often break because deployment scripts package keys in binary DER. Convert them with openssl rsa -in key.der -pubout -out key.pem.

Containers that mount secrets as files can truncate newline endings.

Re-encode the secret, commit a proper PEM file to your secret manager, and redeploy.

Best practices to avoid this error

Always store keys in version-controlled secret managers as PEM. Automate key generation with CI tooling to prevent manual corruption.

Enable MySQL’s require_secure_transport and monitor the error log for code 65.

Galaxy users can add alerts on failed logins to flag malformed key attempts instantly.

Related errors and solutions

Error 2026 - SSL connection error - appears when the public key is missing entirely. Provide the key path in the client options.

Error 1251 - Client does not support authentication protocol - occurs when the client lacks RSA key support. Upgrade the client library or switch authentication plugins.

.

Common Causes

Related Errors

FAQs

Can I disable RSA key exchange to bypass the error?

Yes, switch users to the mysql_native_password plugin, but you lose stronger encryption. Fixing the key is safer.

How do I verify a PEM file quickly?

Use openssl rsa -pubin -in key.pem -text -noout. If the command prints the modulus, the file is valid.

Does this error affect earlier MySQL versions?

No. The code exists only from MySQL 8.0.13 onward where RSA key exchange was added.

How does Galaxy help?

Galaxy’s connection manager validates key paths on save, highlights missing PEM markers, and surfaces MySQL error 65 instantly in the editor.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo