Home >Database >Mysql Tutorial >What is the replacement for the deprecated PASSWORD function in MySQL Server 8.0?

What is the replacement for the deprecated PASSWORD function in MySQL Server 8.0?

Barbara Streisand
Barbara StreisandOriginal
2024-10-29 02:51:30401browse

What is the replacement for the deprecated PASSWORD function in MySQL Server 8.0?

PASSWORD Function Discontinuation in MySQL Server 8.0

In MySQL Server version 8.0, the PASSWORD function has been deprecated and no longer operates as intended. This issue arises when executing queries that rely on the PASSWORD function for password validation.

Error Message

When executing a query that includes the PASSWORD function in MySQL Server version 8.0.12, you may encounter the following error:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near...

Replacement for PASSWORD Function

To resolve this issue, it is recommended to use the following expression as a replacement for the PASSWORD function:

SHA1(UNHEX(SHA1()))

Example

For instance, if you previously had a query like:

SELECT * 
FROM users 
WHERE login = 'FABIO' 
AND pwd = PASSWORD('2018') 
LIMIT 0, 50000

You can replace the PASSWORD function with the expression:

SELECT * 
FROM users 
WHERE login = 'FABIO' 
AND pwd = SHA1(UNHEX(SHA1('2018'))) 
LIMIT 0, 50000

By using the provided replacement expression, you can ensure that your queries continue to function correctly in MySQL Server version 8.0 and avoid the error mentioned above.

The above is the detailed content of What is the replacement for the deprecated PASSWORD function in MySQL Server 8.0?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn