mysqladmin -u username -h hostname -p password "newpwd"
语法参数说明如下:C:\Users\leovo>mysqladmin -u root -p password "rootpwd" Enter password: **** mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.输入 mysqladmin 命令后,按回车键,然后输入 root 用户原来的密码。执行完毕后,密码修改成功,root 用户登录时将使用新的密码。
C:\Users\leovo>mysql -uroot -p Enter password: ******* Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 23 Server version: 5.7.29-log MySQL Community Server (GPL) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.结果显示,root 用户登录成功,所以使用 mysqladmin 命令修改 root 用户密码成功。
UPDATE mysql.user set authentication_string = PASSWORD ("rootpwd) WHERE User = "root" and Host="localhost";
新密码必须使用 PASSWORD() 函数来加密。执行UPDATE语句后,需要执行FLUSH PRIVILEGES语句重新加载用户权限。mysql> UPDATE mysql.user set authentication_string = password ("rootpwd2") -> WHERE User = "root" and Host = "localhost"; Query OK, 1 row affected, 0 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings:0 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.06 sec)结果显示,密码修改成功。而且使用了
FLUSH PRIVILEGES;
语句加载权限。退出后就必须使用新密码来登录了。SET PASSWORD = PASSWORD ("rootpwd");
MySQL> SET PASSWORD = password ("rootpwd3"); Query OK, 0 rows affected (0.00 sec)结果显示,SET 语句执行成功,root 用户的密码被成功设置为“rootpwd3”。
Copyright © 广州京杭网络科技有限公司 2005-2024 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有