Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change mysql user password using command line

I'm trying to update the password for a database user using the command line, and it's not working for me. This is the code I'm using:

mysql> UPDATE user SET password=PASSWORD($w0rdf1sh) WHERE user='tate256'; 

Could someone tell me what's wrong with this code.

like image 930
user3310572 Avatar asked Apr 01 '14 00:04

user3310572


People also ask

How do I change my password policy in MySQL terminal?

To change the default password policy level, we can change the settings at runtime using the command line or in the config file (my. cnf/mysqld. cnf) permanently. Login to MySQL command prompt and execute the below query to view current settings of validate_password.


1 Answers

In your code, try enclosing password inside single quote. Alternatively, as per the documentation of mysql, following should work -

SET PASSWORD FOR 'jeffrey'@'localhost' = PASSWORD('cleartext password');  FLUSH PRIVILEGES; 

The last line is important or else your password change won't take effect unfortunately.

EDIT:

I ran a test in my local and it worked -

mysql>  set password for 'test' = PASSWORD('$w0rdf1sh'); Query OK, 0 rows affected (0.00 sec) 

Mine is version 5. You can use following command to determine your version -

SHOW VARIABLES LIKE "%version%"; 
like image 152
hellboy Avatar answered Sep 25 '22 07:09

hellboy