MySQL 修改用户密码

编程教程 > MySQL (746) 2025-04-16 10:53:11

查询MySQL版本号

select version();
image

根据版本号查找下面的修改密码方式

MySQL 5.7.9以前版本修改密码

use mysql; 
update user set pasword = password("new pasword") where user = "root";
-- 一定要刷新,否则不生效
flush privileges; 

MySQL 5.7.9-8.0版本修改密码

mysql 5.7.9以后废弃了password字段和password()函数;

新增了authentication_string字段表示用户密码

而authentication_string字段下只能是mysql加密后的41位字符串密码

所以需要用下面方式来修改root密码

ALTER user 'root'@'localhost' IDENTIFIED BY 'newpassword';
flush privileges;

或者

update user set authentication_string = password("your new password") where user = "userName";

flush privileges;

MySql 8.X 修改密码

8.x开始修改密码有了变化,修改密码前先检查authentication_string是否为空

authentication_string非空

use mysql; 
-- 将字段置为空
update user set authentication_string='' where user='root';
-- 修改密码为 new pasword
ALTER user 'root'@'localhost' IDENTIFIED BY 'new pasword'; 
flush privileges;

authentication_string空则直接修改:

-- 修改密码为 new pasword
ALTER user 'root'@'localhost' IDENTIFIED BY 'new pasword';
flush privileges;

8.x版本搞定

 

重要提示:所有版本更新最后修刷新下!!!

 


评论
User Image
提示:请评论与当前内容相关的回复,广告、推广或无关内容将被删除。

相关文章
mysql 5.7.9以后废弃了password字段和password()函数;authentication_string:字段表示用户密码,而authenti
MySQL索引优化,MySQL索引类型,MySQL索引怎么用MySQL索引怎么创建这里将会通过一些简单得sql进行讲解
mysql 数据库备份与还原命令1&gtl;导出某个数据库表结构(其他说明:-u 后面的root为用户名,-p后面的password为用户密码,dbname数据库名称)
最近服务器上经常出现mysql进程占CPU100%的情况,使用命令show processlist后,看到出现了很多状态为LOCKED的sql。使用show s
SQL SERVER数据库中SUBSTRING函数的使用SELECT SUBSTRING(a.receiveTime,0,20) formatReceiveTi
sql server 2016数据库导出表数据/表结构1.打开Microsoft SQL Server Management Studio工具选择要导出表的数据