I am unable reset mysql password using below query:
UPDATE mysql.user
SET authentication_string=PASSWORD('root')
WHERE user='root'
and host='localhost';
i am getting below error:
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 '('root') WHERE User = 'root' AND Host = 'localhost'' at line 1
As #spencer7593 points out, the PASSWORD() function was removed in MySQL 8.0 so this code won't work any longer even if it did in previous versions. The syntax error arises because, not recognizing that as a function, the ( character following it is unexpected and a syntax error.
This is because in addition to (previously) being a function it still a keyword.
The way you should be adjusting passwords is either through the mysqladmin command-line tool, or via the SET PASSWORD statement:
SET PASSWORD FOR 'root' = '...'
Related
I'm currently setting a docker to run a mysql container on my computer. ( I'm a windows user, so I downloaded Docker Desktop, and installed wsl2 with ubuntu diro and it runs ).
The problem is the following : when I try to change the 'root' user password of my localhost, I see
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 'IDENTIFIED BY 'any-pwd' at line 1
Here is the command line I try to execute : mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'any-pwd';
I've been following this tutorial from the official mysql documentation : https://dev.mysql.com/doc/mysql-installation-excerpt/8.0/en/docker-mysql-getting-started.html
I also tried to "flush priviliege", but I'm still facing an error : You must SET PASSWORD before executing this statement, (I know, that's what I'm trying to do!)
But the "set password" seemed to be a sql piece of code so I tried the following :
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('password');
And you know what, it works! I had this problem because I use the docker mysql image with 5.6 tag, and so I got to use the last sql command, not the first.
Well there is no question, but I post it here if it can help someone one day!
I've been busting my ass from last two days to update authentication_string of my root user and mysql is throwing ERROR 1064 at my face. I've tried every option I could (of course except the correct one which I don't know XD. After logging in as ROOT, I tried this code.
mysql> UPDATE MYSQL.USER SET AUTHENTICATION_STRING = PASSWORD('OJ') WHERE `USER` = 'ROOT';
And I'm getting following error.
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 '('OJ') WHERE `USER` = 'ROOT'' at line 1
I can't figure out what's going wrong here.
Thank you.
While trying to change mysql password by following steps given in this solution, i got the following error-
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('letsrock') WHERE User = 'root' AND Host = 'localhost';
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 '('letsrock') WHERE User = 'root' AND Host = 'localhost'' at line 1
Is there a new syntax for update command in mysql or what? I am using 8.0.12 version.
Both 'user' and 'host' are reserved words and cannot be used as identifiers without enclosing them in backticks. Like so:
UPDATE mysql.user
SET authentication_string = PASSWORD('letsrock')
WHERE `User` = 'root' AND `Host` = 'localhost';
See: https://dev.mysql.com/doc/refman/8.0/en/keywords.html
I am using mysql version 8.0
From mysql cli I am trying to call the function PASSWORD. So I have used the following command :
mysql > select PASSWORD('123');
But I get the following error in this case :
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 '('123')' at line 1
I have also tries the following :
mysql > select PASSWORD("123");
mysql > select PASSWORD(`123`);
But each one give the same error. I have also googled a lot but could not find any solution for this.
How can I solve this
Regards,
Tanvir
As mysql documentation on the password() function says:
This function was removed in MySQL 8.0.11.
As mysql documentation says, you should use alter user statement to change the password:
ALTER USER syntax is the preferred statement for account alterations, including assigning passwords. For example:
ALTER USER user IDENTIFIED BY 'auth_string'
PASSWORD() was deprecated in 5.7 and removed in version 8. Far more secure ways of handling passwords are available, and you should consider using one.
Updating the ACL system tables directly (or any system tables for that matter) is not a very sustainable practice.
Why would you need to execute
UPDATE mysql.user SET password = hash('clear-text-password') WHERE host = 'foo' and user = 'bar'
followed by a FLUSH PRIVILEGES (!)
when you can just do:
ALTER USER foo#bar IDENTIFIED BY 'clear-text-password' ?
I'm trying to execute
ALTER USER 'root'#'localhost' IDENTIFIED BY 'my_new_password';
but getting
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 'IDENTIFIED BY 'my_new_password'' at line 1
What am i doing wrong?
The way you want to change the password is only valid since MySQL 5.7.6. You can use the SET PASSWORD statement for older versions instead:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('my_new_password');
The ALTER USER statement is available since MySQL 5.7.6. Make sure you are using this version or a newer one to use your statement (thx #Dez).