Change mysql user password using command line

2019-03-09 06:16发布

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.

7条回答
Anthone
2楼-- · 2019-03-09 06:25

In windows 10, just exit out of current login and run this on command line

--> mysqladmin -u root password “newpassword”

where instead of root could be any user.

查看更多
一夜七次
3楼-- · 2019-03-09 06:38

As of MySQL 5.7.6, use ALTER USER

Example:

ALTER USER 'username' IDENTIFIED BY 'password';

Because:

  • SET PASSWORD ... = PASSWORD('auth_string') syntax is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release.

  • SET PASSWORD ... = 'auth_string' syntax is not deprecated, but ALTER USER is now the preferred statement for assigning passwords.

查看更多
太酷不给撩
4楼-- · 2019-03-09 06:41

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%";
查看更多
够拽才男人
5楼-- · 2019-03-09 06:43

Your login root should be /usr/local/directadmin/conf/mysql.conf. Then try following

UPDATE mysql.user SET password=PASSWORD('$w0rdf1sh') WHERE user='tate256' AND Host='10.10.2.30';
FLUSH PRIVILEGES;

Host is your mysql host.

查看更多
倾城 Initia
6楼-- · 2019-03-09 06:45

Note: u should login as root user

 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('your password');
查看更多
何必那么认真
7楼-- · 2019-03-09 06:45

this is the updated answer for WAMP v3.0.6

UPDATE mysql.user 
SET authentication_string=PASSWORD('MyNewPass') 
WHERE user='root';

FLUSH PRIVILEGES;
查看更多
登录 后发表回答