Ubuntu18 重置MySQL8 root密码

本文档介绍了在Ubuntu 18.04上重置MySQL 8.0.19 root密码的两种方法。当初始密码为空且无法使用'mysql -u root --skip-password'登录时,提供了跳过权限验证的临时启动和修改密码的步骤,以及通过定义初始化文件重置密码的尝试,但后者未能成功。
摘要由CSDN通过智能技术生成

问题

购买云服务器后,选择了带MySQL环境的镜像,查看日志知道初始密码是空,但是使用’mysql -u root --skip-password’ 无法登陆数据库。
官方参考:2.10.4 Securing the Initial MySQL Account

# 查看MySQL安装日志
root@VM-0-16-ubuntu:/data# head /var/log/mysql/error.log|grep -E 'root' --color=auto
2020-02-29T14:35:51.914062Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

解决方案

操作环境:Ubuntu 18.04 + MySQL 8.0.19

方案1 跳过权限验证

命令摘要:

mysqld --user=mysql --skip-grant-tables
mysql
mysql> flush privileges;
mysql> alter user 'root'@'localhost' identified by '123456';

详细步骤:

  1. 跳过权限验证方式启动MySQL服务
root@VM-0-16-ubuntu:/data# mysqld --user=mysql --skip-grant-tables

启动成功后的日志信息(ready for connections):

root@VM-0-16-ubuntu:/data# tail -f /var/log/mysql/error.log
2020-05-25T11:13:00.156006Z 0 [System] [MY-010931]
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值