旧版本修改 root 密码
- MySQL 5.7.6 and newer as well as MariaDB 10.1.20 and newer
1
2
|
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;
|
- MySQL 5.7.5 and older as well as MariaDB 10.1.20 and older
1
2
|
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
FLUSH PRIVILEGES;
|
Ubuntu 下 MySQL 8.0 以上版本修改 root 密码
- MySQL 8 默认不开启 root 用户,默认用户是
debian-sys-maint
,其默认密码存储在 /etc/mysql/debian.conf
中
- MySQL 8 已经抛弃了
PASSWORD()
函数。
- MySQL 8 的 user 表已经没有 password 字段了,使用
authentication_string
存储密码 hash
在 /etc/mysql/debian.conf
中查看 MySQL debian-sys-maint
用户的密码,登录上之后,修改 root 的密码
1
2
|
alter user 'root'@'localhost' identified with mysql_native_password by 'passwd';
flush privileges;
|
然后就可以用 root 用户登录了。
参考链接
文章作者
bwangel
上次更新
2022-03-09
许可协议
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 CN 许可协议。转载请注明出处