...
Quickstart: Click "regen" multiple times, then click "copy" to copy the MySQL user password to your clipboard. Adjust parameters below if needed.
How to set a MySQL User Password
Use the generated password in the following SQL commands:
CREATE USER 'user'@'hostname' IDENTIFIED BY '...';
Replace 'user' and 'hostname' with your desired username and host.
ALTER USER 'user'@'hostname' IDENTIFIED BY '...';
Replace 'user' and 'hostname' with the existing username and host.
MySQL Password Hash
Turn a password into the hash MySQL stores, so your SQL never contains the plaintext. The hashing runs in this page's JavaScript. A password you type here is not sent anywhere.
...
...

Generate strong & secure random passwords for your MySQL database users. This tool creates strong, secure, random plain text passwords using crypto.getRandomValues, the browser's cryptographically secure random number generator, without sending the password over the internet or storing the generated password on a server. Whether you need to meet strict MySQL password requirements or reset MySQL password credentials, this generator helps you secure MySQL database accounts with high-entropy passwords. If you are still uncomfortable using this utility you can generate multiple passwords, save them to your device and use different parts from each to create a unique password.
I developed this password generator because security for database users matters. Every character comes straight from the browser's cryptographically secure random number generator, and each one is equally likely. By generating multiple passwords, saving them locally, and then perhaps even manually combining parts, you can achieve a very high degree of trust in your MySQL user credentials. This tool is especially useful when you need to quickly reset MySQL password values or create new accounts that meet MySQL password requirements for length and complexity.
This page is intentionally kept simple to minimize any potential attack surface. All password generation is done in-browser; no server requests are made when you click "generate", "copy", or modify parameters.
Common MySQL Password Errors
When setting or using MySQL passwords, you may encounter these common errors:
- ERROR 1819: Your password does not satisfy the current policy requirements - This means MySQL's password validation plugin is enabled and your password doesn't meet the requirements (length, complexity, etc.). Check your validation settings with
SHOW VARIABLES LIKE 'validate_password%';or generate a longer, more complex password. - ERROR 1045: Access denied for user - This typically means the password is incorrect, the user doesn't exist, or the host doesn't match. Remember that
'user'@'localhost'and'user'@'%'are treated as different accounts in MySQL. - Special character issues in shell/command line - If your password contains special characters like
!,$,', or\, you may need to escape them or use single quotes in your shell. When using SQL commands directly, always wrap passwords in single quotes:IDENTIFIED BY 'password'. - Password works in SQL but not in connection strings - Some characters may need URL encoding in connection strings (e.g.,
@becomes%40). Check your database driver's documentation for proper escaping.
Most apps talk to more than one database, and each one has its own quirks with passwords in connection strings. The MongoDB password generator gives you the percent-encoded form for mongodb+srv:// URIs, the Redis password generator writes the requirepass and ACL SETUSER lines, and the SQL Server password generator makes passwords that always pass CHECK_POLICY.
MySQL Password Hash Generator: Creating Users Without the Plaintext
Most of the time you should just write IDENTIFIED BY 'password' and let MySQL do the hashing. The server already keeps that password out of its own logs: MySQL rewrites the password in CREATE USER, ALTER USER and SET PASSWORD statements before they reach the general query log, the slow query log and the binary log. The mysql client also skips any statement matching *IDENTIFIED* or *PASSWORD* when it writes its history file.
The problem is everything that isn't MySQL. The hash panel above exists for those cases.
When I pre-hash a MySQL password
- Provisioning scripts and migrations that live in Git. An init SQL file for a Docker image, a Flyway or Liquibase migration, a seed script. A hash in a repo still isn't great, but a plaintext password in a repo is how you end up rotating credentials on a Saturday.
- Config management. Ansible, Terraform, Puppet and friends love to echo rendered templates into CI output and write them to state files. If the SQL they run only contains a hash, that's what leaks.
- Handing SQL to someone else. If a DBA or another team runs account changes for you, send them
IDENTIFIED WITH ... AS ...and give the actual password straight to the application's secret store. Nobody in the middle ever sees it. - Your own tooling. Query consoles, audit proxies, ticket comments and chat logs don't know they should redact
IDENTIFIED BY. The MySQL manual also notes that statements taking a hash are not rewritten in logs, which is fine when the thing being logged is a hash.
One caution before you get too comfortable: a password hash is still a secret. Anyone holding it can run an offline guessing attack. With a long random password from the generator at the top of this page, that attack goes nowhere. With Summer2024!, it goes somewhere quickly.
How caching_sha2_password stores a password
caching_sha2_password is the default authentication plugin in MySQL 8.0 and later. The value it keeps in the authentication_string column of mysql.user is 70 bytes long, and I built the panel above by reading MySQL's own source (sql/auth/sha2_password.cc and mysys/crypt_genhash_impl.cc):
$A$: the digest type.Ameans SHA-256.005$: the number of rounds in thousands, so 5,000. This comes from thecaching_sha2_password_digest_roundsserver variable, and 5,000 is the default.- 20 bytes of random salt. Each byte is between 1 and 127 and is never
$, which means the salt can include control characters. - 43 characters of digest. This is the same SHA-256 crypt algorithm Linux uses for
$5$passwords in/etc/shadow, except MySQL feeds it a 20-byte salt instead of stopping at 16.
Because the salt can contain unprintable bytes, you can't safely paste the hash inside quotes. MySQL accepts a hexadecimal literal instead, which is what the panel produces:
CREATE USER 'app'@'10.0.0.%'
IDENTIFIED WITH caching_sha2_password
AS 0x24412430303524...;
The hex literal must not be quoted. MySQL stores the bytes as-is. It does not hash them again, so if you paste in something that isn't a valid hash, you just get an account nobody can log in to. If you want to see a hash MySQL made itself in the same form, run SET print_identified_with_as_hex = ON; and then SHOW CREATE USER 'app'@'10.0.0.%';.
There is also a length limit worth knowing: caching_sha2_password accepts passwords up to 256 bytes. I tried 257 on MySQL 8.4 and got ERROR 1396. The panel refuses anything over 256 bytes for the same reason.
Why the first login needs TLS or an RSA key
The "caching" part of the name is an in-memory cache on the server. After a user logs in successfully once, the server keeps a fast SHA-256 based digest of their password, and later logins use a challenge and response against that cache. The password never crosses the wire.
The cache starts empty for an account after it's created, after its password changes, after RENAME USER, after FLUSH PRIVILEGES, and after a server restart. A salted 5,000-round hash can't check a challenge response, so for that first login the server asks the client for the actual password. MySQL will only accept it over a secure connection (TLS, a Unix socket file, or shared memory) or encrypted with the server's RSA public key. Otherwise you get this:
ERROR 2061 (HY000): Authentication plugin 'caching_sha2_password'
reported error: Authentication requires secure connection.
I tested all of this on MySQL 8.4 with an account created from this page's hash. Unencrypted with no RSA key: that error. Unencrypted with --get-server-public-key: logged in. Unencrypted again right afterward: logged in, because the cache now had the account. After FLUSH PRIVILEGES: the error came back. If an app connects fine for weeks and then fails after a restart, this is usually why. Use TLS and it stops mattering.
How mysql_native_password stores a password
The legacy plugin is much simpler. It stores * followed by the uppercase hex of SHA1(SHA1(password)), 41 characters in total. There is no salt, so the same password gives the same hash on every server in the world. That also means precomputed tables work against it, and two SHA-1 calls are very cheap to guess against.
At login, the client sends SHA1(password) XOR SHA1(nonce + SHA1(SHA1(password))). The server recovers SHA1(password), hashes it once more and compares. The stored hash alone isn't enough to log in, but the stored hash plus one captured unencrypted login is, because together they give up SHA1(password).
Its status, per the MySQL manual: deprecated in 8.0.34, disabled by default in 8.4, and removed in 9.0. On 8.4 you can still turn it on with --mysql-native-password=ON on the command line or mysql_native_password=ON under [mysqld]. Without that, creating one of these accounts fails with ERROR 1524 (HY000): Plugin 'mysql_native_password' is not loaded.
If you want to make this hash offline without a browser, it's one line of Python:
python3 -c "import hashlib,getpass; p=getpass.getpass().encode(); print('*'+hashlib.sha1(hashlib.sha1(p).digest()).hexdigest().upper())"
For a caching_sha2_password hash without this page, the least fiddly offline option is a throwaway MySQL container. Create the user with IDENTIFIED BY, run SHOW CREATE USER with print_identified_with_as_hex turned on, copy the AS 0x... part, and delete the container.
Migrating users off mysql_native_password
Start by finding them:
SELECT user, host FROM mysql.user WHERE plugin = 'mysql_native_password';
There is no way to convert an existing native hash into a caching_sha2_password hash. SHA-1 only goes one way, and the new format needs the original password. So each account needs a new password (or the old one, if you still have it):
ALTER USER 'app'@'10.0.0.%' IDENTIFIED WITH caching_sha2_password BY 'new-password';
Or use the ALTER USER ... AS 0x... statement from the panel above so the plaintext stays out of the migration script. Before you flip an account, make sure the client library connecting with it supports caching_sha2_password, and that it connects over TLS or can fetch the server's RSA key. Very old drivers don't. Do the whole migration while you're still on 8.4 with the native plugin enabled, because 9.0 doesn't have the plugin to fall back on.
MariaDB is different
MariaDB went its own way. On MariaDB 11.4, which I tested, a new account defaults to mysql_native_password, SELECT PASSWORD('...') returns the same * hash this page makes, and caching_sha2_password is listed as not installed. So the native hash from this page works on MariaDB, but the $A$005$ hash is for MySQL only. MariaDB's syntax is also a little different:
CREATE USER 'app'@'%' IDENTIFIED BY PASSWORD '*0DA3D1CD83EC6FAE79E8E3859E146E74E1CE416A';
-- or
CREATE USER 'app'@'%' IDENTIFIED VIA mysql_native_password USING '*0DA3D1CD83EC6FAE79E8E3859E146E74E1CE416A';
If you want something stronger on MariaDB, it ships an ed25519 plugin. Load it once with INSTALL SONAME 'auth_ed25519';, then CREATE USER 'app'@'%' IDENTIFIED VIA ed25519 USING PASSWORD('...');. That form has the server do the hashing, so the plaintext is in the statement, and this page doesn't generate ed25519 hashes.
MySQL User Password FAQ
Why are strong passwords crucial for MySQL users?
MySQL databases often store sensitive and valuable data. A compromised MySQL user account can lead to data breaches, data corruption, unauthorized access, or denial of service. Strong, unique passwords are the first line of defense.
What makes a password strong for a MySQL user?
A strong MySQL password should be:
- Long: Aim for at least 16-32 characters. MySQL supports passwords up to 1024 characters depending on the authentication plugin.
- Complex: Include a mix of uppercase letters, lowercase letters, numbers, and special symbols allowed by MySQL.
- Random: Avoid predictable patterns, dictionary words, or information related to the server or database. This generator helps ensure randomness.
- Unique: Each MySQL user should have a completely unique password. Do not reuse passwords across different users or systems.
How long can a MySQL password be?
The maximum password length depends on the authentication plugin used by the MySQL user account. caching_sha2_password, the default, accepts up to 256 bytes (MySQL 8.4 rejected a 257-byte password when I tried). mysql_native_password accepted a 2,000-character password in the same test. Note that the limit is bytes, not characters, so non-ASCII characters use it up faster. It's good practice to use passwords that are long enough to be secure (e.g., 32+ characters) but manageable.
Which characters are allowed in MySQL passwords?
MySQL passwords can generally contain any ASCII characters, including uppercase and lowercase letters, numbers, and most punctuation/special symbols. However, some characters might need to be escaped if setting the password directly in an SQL statement (e.g., single quotes, backslashes). When using this generator, the output is plain text, suitable for direct use or copying into MySQL client tools or scripts.
Should I use the same password for different MySQL users or different database servers?
No. Each MySQL user, on every MySQL server instance, should have a unique password. If one user account or server is compromised, unique passwords prevent attackers from easily accessing other users or servers.
Is this MySQL password generator safe?
Yes. This generator runs entirely in your web browser (client-side). No passwords or parameters are sent over the internet, and nothing is stored on our servers. The generated password is only visible to you.
How do I apply the generated password to a MySQL user?
You can set or change a MySQL user's password using SQL commands like:
- For new users:
CREATE USER 'username'@'host' IDENTIFIED BY 'generated_password'; - For existing users:
ALTER USER 'username'@'host' IDENTIFIED BY 'generated_password';
Replace 'username', 'host', and 'generated_password' with the appropriate values. Always ensure you are connected to the correct MySQL server with sufficient privileges.
What are MySQL authentication plugins and why do they matter for passwords?
Authentication plugins determine how MySQL stores and verifies user passwords. Modern plugins like caching_sha2_password (default in MySQL 8.0+) offer stronger hashing and security than older ones like mysql_native_password. Using strong plugins is essential for password security.
How can I check which authentication plugin a MySQL user is using?
You can query the mysql.user table: SELECT user, host, plugin FROM mysql.user WHERE user = 'your_username';
How do I generate a MySQL password hash?
Use the MySQL Password Hash panel on this page. Pick caching_sha2_password (MySQL 8.0 and later) or mysql_native_password (legacy), then hash either the generated password or one you type. You get a ready CREATE USER ... IDENTIFIED WITH ... AS ... statement. The hashing runs in your browser, and a password you type is not sent anywhere.
Why is the caching_sha2_password hash a 0x hex value?
The stored value includes a 20-byte random salt, and those bytes can be control characters that don't survive copy and paste inside quotes. MySQL accepts the hash as a hexadecimal literal in IDENTIFIED WITH caching_sha2_password AS 0x.... Don't put quotes around it. SHOW CREATE USER prints hashes the same way when print_identified_with_as_hex is on.
Why do I get a different caching_sha2_password hash every time for the same password?
Each hash gets a new random salt, and the salt is part of the stored value. All of them verify the same password. mysql_native_password has no salt, which is why its hash never changes and one of the reasons it was retired.
Can I convert a mysql_native_password hash to caching_sha2_password?
No. The native hash is SHA1(SHA1(password)), and there's no way back to the password from it, which the new format needs. Set the password again with ALTER USER ... IDENTIFIED WITH caching_sha2_password BY '...' or with a hash from this page.
Does a MySQL password hash from this page work on MariaDB?
The mysql_native_password hash does. It's the same value MariaDB's PASSWORD() function returns, and you can use it with IDENTIFIED BY PASSWORD '*...'. The caching_sha2_password hash is for MySQL only. On MariaDB 11.4 that plugin isn't installed.
Besides strong passwords, what else can I do to secure MySQL users?
- Principle of Least Privilege: Grant each user only the permissions (privileges) absolutely necessary for their tasks. Avoid granting
ALL PRIVILEGESunless essential. - Host Restriction: Define users with specific hostnames (e.g.,
'user'@'appserver.example.com') rather than wildcards ('user'@'%') to limit where connections are accepted from. - Regular Audits: Periodically review user accounts, their privileges, and last login times. Remove unused accounts.
- Secure Connections: Enforce SSL/TLS for connections to MySQL to encrypt data in transit.
- Firewall: Restrict network access to the MySQL port (default 3306) to only trusted IP addresses/networks.
- Software Updates: Keep your MySQL server software patched and up-to-date.
Should I store MySQL passwords in application configuration files?
If you must store MySQL passwords in configuration files, ensure the files have strict permissions, are not checked into version control (use environment variables or secret management systems instead for production), and consider encrypting sensitive configuration sections if possible.
What about the 'root' user in MySQL?
The root user is highly privileged. It's critical to set a very strong password for all root accounts immediately after MySQL installation. For applications, create dedicated, less-privileged users instead of using root.
How do I reset a forgotten MySQL root password?
If you've forgotten your MySQL root password, you can reset it using these steps:
- Stop the MySQL server:
- Linux:
sudo systemctl stop mysqlorsudo service mysql stop - Windows:
net stop MySQL80(or your MySQL service name)
- Linux:
- Start MySQL in safe mode (skipping grant tables):
- Linux:
sudo mysqld_safe --skip-grant-tables & - Windows:
mysqld --skip-grant-tables
- Linux:
- Connect without a password:
mysql -u root - Reset the password:
FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_strong_password'; FLUSH PRIVILEGES; - Restart MySQL normally: Stop the safe mode instance and restart MySQL with normal settings.
Security Warning: Only perform this on a server you have physical or administrative access to. Never leave MySQL running in safe mode.
How do I test if my new MySQL password works?
After setting a new password, test it immediately to verify it works:
- From command line:
mysql -u username -p -h hostname - You'll be prompted to enter the password. If successful, you'll see the MySQL prompt:
mysql> - Expected errors if password is wrong:
ERROR 1045 (28000): Access denied for user 'username'@'host' (using password: YES) - Test from your application: Use your application's database connection function with the new password to ensure it connects properly before deploying to production.
If you can't connect, double-check: (1) the username and host match exactly, (2) you're copying the entire password without extra spaces, and (3) the user has appropriate host permissions.
What is MySQL's password validation plugin?
The validate_password component (MySQL 8.0+) or validate_password plugin (MySQL 5.7) enforces password strength requirements to ensure secure MySQL passwords.
Check if it's enabled: SHOW VARIABLES LIKE 'validate_password%';
Common settings:
validate_password.length- Minimum password length (default: 8)validate_password.policy- Strength level: LOW (0), MEDIUM (1), or STRONG (2)validate_password.mixed_case_count- Required uppercase and lowercase lettersvalidate_password.number_count- Required numeric digitsvalidate_password.special_char_count- Required special characters
If you get ERROR 1819 when setting a password, your password doesn't meet these requirements. Use this generator to create a longer, more complex password that will satisfy the policy.
Do MySQL passwords expire?
Yes, MySQL supports password expiration as a security feature to force regular password changes.
Check expiration settings:
- Global default:
SHOW VARIABLES LIKE 'default_password_lifetime';(0 = never expire, otherwise days until expiration) - Per-user status:
SELECT user, host, password_expired, password_lifetime FROM mysql.user;
Set password expiration:
- Expire immediately:
ALTER USER 'user'@'host' PASSWORD EXPIRE; - Expire in 90 days:
ALTER USER 'user'@'host' PASSWORD EXPIRE INTERVAL 90 DAY; - Never expire:
ALTER USER 'user'@'host' PASSWORD EXPIRE NEVER; - Use global default:
ALTER USER 'user'@'host' PASSWORD EXPIRE DEFAULT;
For automated service accounts, consider using PASSWORD EXPIRE NEVER and implement your own password rotation schedule instead.
How do I use this password in my application code?
After generating a strong password, you'll need to configure your application's database connection. Here are examples for common languages:
Python (mysql-connector-python):
import mysql.connector
connection = mysql.connector.connect(
host='hostname',
user='username',
password='your_generated_password',
database='database_name'
)
PHP (PDO):
$dsn = "mysql:host=hostname;dbname=database_name";
$username = "username";
$password = "your_generated_password";
$pdo = new PDO($dsn, $username, $password);
Node.js (mysql2):
const mysql = require('mysql2');
const connection = mysql.createConnection({
host: 'hostname',
user: 'username',
password: 'your_generated_password',
database: 'database_name'
});
Security Best Practices: Never hardcode passwords in your source code. Use environment variables, configuration files with restricted permissions, or secret management services (like AWS Secrets Manager, HashiCorp Vault, etc.) to store MySQL credentials securely.
Also check out the PostgreSQL Password Generator, SQL Server Password Generator, MongoDB Password Generator, Redis Password Generator, General Strong Password Generator, and Random Passphrase Generator, or browse all the free tools.
-Sethers