blank的编程之路


  • 首页

  • 归档

  • 搜索
consul atomikos mybatisplus druid nexus nas named bind mysqldump acme.sh Dockerfile rsync keepalived swarm kibana ubuntu linux scp bugfix https ssl certbot curl gogs adminer harbor yum portainer python kubernetes idea java springboot maven docker-compose redis nginx mysql brew git chocolatey jenkins elasticsearch docker haproxy rabbitmq centos

快速重置MySQL root 密码

发表于 2019-03-13 | 分类于 运维 | 0 | 阅读次数 381

编辑 MySQL 配置文件/etc/my.cnf,在[mysqld]下添加一行skip-grant-tables

vim /etc/my.cnf

[mysqld]
#...
skip-grant-tables
#...

重启MySQL

systemctl restart mysqld

终端输入 mysql 直接登录MySQL数据库:

mysql

切换到mysql数据库

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed

重置 root 密码

(需要注意的是
在MySQL5.7之后
已经没有password这个字段了
password字段改成了authentication_string
修改密码我们要修改这个字段的值)

mysql> update user set authentication_string=password('新密码') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

还原修改 /etc/my.cnf 文件将之前添加的skip-grant-tables 这句话注释掉 下次忘记密码还可以用

vim /etc/my.cnf

[mysqld]
#...
#skip-grant-tables
#...

DONE

  • 本文作者: blank
  • 本文链接: https://blankhang.com/2019/03/13/1552469219231
  • 版权声明: 本博客所有文章除特别声明外,均采用CC BY-NC-SA 3.0 许可协议。转载请注明出处!
# consul # atomikos # mybatisplus # druid # nexus # nas # named # bind # mysqldump # acme.sh # Dockerfile # rsync # keepalived # swarm # kibana # ubuntu # linux # scp # bugfix # https # ssl # certbot # curl # gogs # adminer # harbor # yum # portainer # python # kubernetes # idea # java # springboot # maven # docker-compose # redis # nginx # mysql # brew # git # chocolatey # jenkins # elasticsearch # docker # haproxy # rabbitmq # centos
yum 快速安装官方MySQL 并创建用户配置权限
CentOS7 查看和关闭系统防火墙
© 2022 blank
Everything is energy and everything has a frequency