totn MySQL Functions

MySQL: PASSWORD Function

This MySQL tutorial explains how to use the MySQL PASSWORD function with syntax and examples.

Description

The MySQL PASSWORD function is used by the authentication system in MySQL to generate a hashed password from a plaintext password string using more powerful hashing techniques that were introduced in MySQL 4.1. To use older hashing techniques, use the OLD_PASSWORD function.

Syntax

The syntax for the PASSWORD function in MySQL is:

PASSWORD( string )

Parameters or Arguments

string
A plaintext password string that is the source to create an encrypted/hashed password in MySQL.

Note

  • The PASSWORD function will return NULL, if the string is NULL.
  • The PASSWORD function performs encryption one-way.
  • The PASSWORD function is used by the authentication system in MySQL to store passwords.
  • Do not use th PASSWORD function in your own application, use the MD5 or SHA1 functions instead.
  • See also the ENCRYPT function.

Applies To

The PASSWORD function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1

Example

Let's look at some MySQL PASSWORD function examples and explore how to use the PASSWORD function in MySQL.

For example:

mysql> SELECT PASSWORD('abc');
Result: '*0D3CED9BEC10A777AEC23CCC353A8C08A633045E'

mysql> SELECT PASSWORD('password');
Result: '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'

mysql> SELECT PASSWORD('techonthenet');
Result: '*0886644237EED5C45BE221093802B5AB0C06D2D0'

mysql> SELECT PASSWORD(NULL);
Result: NULL