How does MySQL password hashing work?

MySQL uses cryptographic hashing to securely store user passwords. Rather than storing passwords in plain text, MySQL converts them into fixed-length hash strings using one-way mathematical functions. When a user attempts to log in, MySQL hashes the provided password and compares it to the stored hash. If they match, authentication succeeds. This approach ensures that even if someone gains access to the database, they cannot directly read user passwords.

The modern MySQL Native Password algorithm applies SHA-1 hashing twice: SHA1(SHA1(password)). This double-hashing provides an additional layer of security. The resulting 40-character hexadecimal string is prefixed with an asterisk (*) to indicate it's a hashed password, producing values like *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19.

Tool description

This MySQL Password Hash Generator creates authentication hashes compatible with MySQL and MariaDB databases. Enter any password and instantly generate the corresponding hash that can be used directly in SQL statements like CREATE USER or ALTER USER. The tool supports both the modern MySQL Native Password format (MySQL 4.1 and later) and the legacy Old Password format for older systems.

Examples

MySQL Native Password (4.1+):

  • Input: mypassword
  • Output: *FABE5482D5AADF36D028AC443D117BE1180B9725

Old Password (Pre-4.1):

  • Input: mypassword
  • Output: 162eebfb6477e5d3

SQL Usage:

-- Create user with hashed password
CREATE USER 'username'@'localhost' IDENTIFIED BY PASSWORD '*FABE5482D5AADF36D028AC443D117BE1180B9725';

-- Update existing user password
ALTER USER 'username'@'localhost' IDENTIFIED BY PASSWORD '*FABE5482D5AADF36D028AC443D117BE1180B9725';

Features

  • MySQL Native Password: Generates SHA1(SHA1(password)) hashes for MySQL 4.1+ and MariaDB
  • Legacy Old Password: Supports pre-MySQL 4.1 hash format for backward compatibility
  • Real-time hashing: Hash updates instantly as you type
  • Password visibility toggle: Show or hide password input for easier entry
  • One-click copy: Quickly copy the generated hash to clipboard

Use cases

  • Creating MySQL user accounts with pre-hashed passwords in deployment scripts
  • Migrating users between MySQL databases while preserving password hashes
  • Testing and validating MySQL authentication configurations
  • Generating password hashes for MySQL-compatible applications
  • Troubleshooting authentication issues by comparing expected vs actual hashes

Supported hash formats

Format Algorithm MySQL Version Output Example
MySQL Native Password SHA1(SHA1(password)) 4.1+ *2470C0C06DEE42FD...
Old Password Custom hash Pre-4.1 6f8c114b58f2ce9e

Security considerations

The MySQL Native Password hash is the recommended format for all modern MySQL and MariaDB installations. The Old Password format is considered insecure and should only be used for compatibility with legacy systems that cannot be upgraded. MySQL 8.0 introduced caching_sha2_password as the new default, but mysql_native_password remains widely supported and commonly used.