MySql8.0修改root密码

MySql8.0修改root密码

原创 于 2019-06-20 12:11:04 发布 · 7.8w 阅读 · 126 · 292 · CC 4.0 BY-SA版权 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 文章链接:https://blog.csdn.net/wolf131721/article/details/93004013

MySQL 5.7 的版本,因为在user表中没有password字段,一直使用下边的方式来修改root密码

use mysql; 
update user set authentication_string = password(“root”) where user = “root”;

现在要用MySQL8.0.11版本,装好MySQL后用上边方法修改密码,一直报错。后来去掉password()函数后,没有报错,但是输入密码时不对。

查阅后才知道在mysql 5.7.9以后废弃了password字段和password()函数;authentication_string:字段表示用户密码,而authentication_string字段下只能是mysql加密后的41位字符串密码。所以需要用一下方式来修改root密码:

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

MySql 从8.0 开始修改密码有了变化,在user表加了字段authentication_string,修改密码前先检查authentication_string是否为空

1、如果不为空

use mysql; 

update user set authentication_string='' where user='root';--将字段置为空

ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密码为root

2、如果为空,直接修改

ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密码为root

如果出现如下错误

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;

需要执行

flush privileges;

然后再执行

ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密码为root
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇