Common SQL Errors

MySQL Error 1372: ER_PASSWD_LENGTH - How to Fix and Prevent

Galaxy Team
August 6, 2025

<p>MySQL raises ER_PASSWD_LENGTH (error 1372) when a SET PASSWORD or GRANT statement supplies a password hash that is not the required hexadecimal length.</p>

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 code 1372?

<p>MySQL Error 1372: ER_PASSWD_LENGTH occurs when the password hash in a SET PASSWORD or GRANT statement is not the expected 41-digit (pre-5.7) or 43-digit (5.7+) hexadecimal string. Regenerate the hash with the PASSWORD() or SHA2() function and rerun the statement to resolve the issue.</p>

Error Highlights

Typical Error Message

Password hash should be a %d-digit hexadecimal number

Error Type

Authentication Error

Language

MySQL

Symbol

ER_PASSWD_LENGTH

Error Code

1372

SQL State

HY000

Explanation

Table of Contents

What does MySQL Error 1372 (ER_PASSWD_LENGTH) mean?

MySQL throws this error when a password hash supplied in a SET PASSWORD, CREATE USER, or GRANT statement is the wrong length. Pre-5.7 servers expect a 41-digit hexadecimal hash that begins with an asterisk. Servers using mysql_native_password after 5.7 expect a 43-digit hash. Any deviation triggers error 1372.

The engine validates the supplied string before updating mysql.user. If the string has missing characters, extra spaces, or non-hexadecimal symbols, validation fails and the statement aborts with ER_PASSWD_LENGTH.

When does the problem surface?

The error typically appears during migrations, scripted user creation, or automated CI pipelines where password hashes come from environment variables or legacy dumps. It may also surface after copying user rows between servers running different major versions.

Why should you fix it quickly?

Failing to set a password halts user creation and leaves accounts unusable. Automation scripts stop, deployments roll back, and team members lose access until the hash is corrected.

Key takeaways

Always provide a hash that matches the server’s authentication plugin requirements, strip surrounding quotes correctly, and verify no invisible characters are present.

Common Causes

Incorrect hash length

Supplying a 40 or 42 digit string instead of the exact 41 or 43 required length causes immediate failure.

Wrong authentication plugin

Restoring a 41-digit mysql_native_password hash on a server that defaults to caching_sha2_password results in a length mismatch.

Copy-paste artefacts

Extra spaces, line breaks, or hidden characters added when copying the hash from logs or files inflate its length.

Truncated environment variables

Shell escaping or CI variable limits may cut characters from the end of the hash.

Related Errors

Error 1133: ER_NONEXISTING_USER

Raised when SET PASSWORD references a user that does not exist. Create the user first.

Error 1396: ER_CANNOT_USER

Occurs when you try to modify a user you do not have privileges for. GRANT appropriate rights or connect as root.

Error 1820: ER_PASSWORD_EXPIRE_ANONYMOUS_USER

Shown when attempting to set a password for an anonymous account without proper clauses.

FAQs

How many characters should a mysql_native_password hash have?

Exactly 41 characters, including the leading asterisk, for versions before 5.7.6 and 43 characters for 5.7.6+.

Can I store plaintext passwords in scripts?

Avoid plaintext. Generate the hash inside MySQL or use environment variables and encryption tools to protect credentials.

Does SET PASSWORD accept SHA2 hashes?

Yes, for accounts using caching_sha2_password. Provide the plaintext password and let MySQL hash it, or use ALTER USER with IDENTIFIED BY.

How does Galaxy help prevent ER_PASSWD_LENGTH?

Galaxy’s editor validates password commands against the target server version and highlights incorrect hash lengths before execution, reducing runtime errors.

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