Home  >  Article  >  Database  >  How to Fix PASSWORD Function Issues in MySQL Server 8.0: A Syntax Guide

How to Fix PASSWORD Function Issues in MySQL Server 8.0: A Syntax Guide

Barbara Streisand
Barbara StreisandOriginal
2024-10-31 07:13:02577browse

How to Fix PASSWORD Function Issues in MySQL Server 8.0: A Syntax Guide

Troubleshoot PASSWORD Function Issues in MySQL Server 8.0

When attempting to execute the PASSWORD function in MySQL Server version 8.0.12, certain scenarios may trigger an error. This article aims to address such issues and provide a viable solution.

Error Code 1064

If you encounter the error "Error Code: 1064. You have an error in your SQL syntax...", it indicates an issue with the syntax of your query. Specifically, the PASSWORD function syntax has changed in MySQL Server version 8.0.

New Syntax

With MySQL Server 8.0, the PASSWORD function has been deprecated and replaced with a different hashing mechanism. To maintain compatibility, you should use the following syntax to generate a hash equivalent to the one produced by the PASSWORD function in previous versions:

CONCAT('*', UPPER(SHA1(UNHEX(SHA1('my_password')))))

Example

In the provided query, "pwd = PASSWORD('2018')" represents the comparison of the "pwd" column with a static password. To retrieve users with the password '2018' using the new syntax, you can modify the query as follows:

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

The above is the detailed content of How to Fix PASSWORD Function Issues in MySQL Server 8.0: A Syntax Guide. 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