3

I forgot the password for mysql, so i was trying to change it using following steps -

1) Stop Mysql server

2)Start server in safe mode by using sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

3) Open mysql command line using sudo /usr/local/mysql/bin/mysql -u root

4) Update password using UPDATE mysql.user SET authentication_string=PASSWORD('NewPassword') WHERE User='root';

But on this step i am getting the following error message -

ERROR 1064 (42000): 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 '('NewPassword') WHERE User='root'' at line 1

Can someone tell how to resolve this error?

monster
  • 808
  • 10
  • 23

2 Answers2

7

On 8.0.15 (maybe already before that version) the PASSWORD() function does not work, as mentioned in the comments below. You have to use:

UPDATE mysql.user SET authentication_string='password' WHERE User='root';

Original answer here

Serhii Hrabas
  • 401
  • 1
  • 5
  • 12
0

As problem states clearly, its incorrect syntax. You should be using official MYSQL procedure to reset password, that includes create text file with command and then restarting the mysqld with text file input with mysqld --init-file=/home/me/mysql-init &' command.

Refer official root password reset options for unix [here][1].

[1]https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

Red Boy
  • 5,429
  • 3
  • 28
  • 41