首页 技术 正文
技术 2022年11月16日
0 收藏 474 点赞 4,398 浏览 1482 个字

第一步:修改配置文件免密码登录mysql

vim /etc/my.cnf

Mysql8 忘记Root密码(转)

1.2 在 [mysqld]最后加上如下语句 并保持退出文件;

skip-grant-tables

Mysql8 忘记Root密码(转)

1.3 重启mysql服务:

service mysqld restart

第二步免密码登录到mysql上;直接在命令行上输入:

  1.  mysql
  2.  //或者
  3.  mysql -u root -p
  4.  //password直接回车

第三步: 给root用户重置密码;

3.1 首先查看当前root用户相关信息,在mysql数据库的user表中;

select host, user, authentication_string, plugin from user;

host: 允许用户登录的ip‘位置’%表示可以远程;

user:当前数据库的用户名;

authentication_string: 用户密码;在mysql 5.7.9以后废弃了password字段和password()函数;

plugin: 密码加密方式;

Mysql8 忘记Root密码(转)

3.2 如果当前root用户authentication_string字段下有内容,先将其设置为空;

  1.  use mysql;
  2.  update user set authentication_string=” where user=’root’;

3.3 退出mysql, 删除/etc/my.cnf文件最后的 skip-grant-tables 重庆mysql服务;

3.4 使用root用户进行登录,因为上面设置了authentication_string为空,所以可以免密码登录;

  1.  mysql -u root -p
  2.  passwrod:直接回车;

3.5使用ALTER修改root用户密码;

 ALTER user 'root'@'localhost' IDENTIFIED BY 'Qian123#'

至此修改成功; 从新使用用户名密码登录即可;

修改中遇到的问题:

1. 根据网上的这篇文章进行修改,报错;

网友文章:Linux-CentOS7下修改root密码和密码过期问题

在使用这句话修改密码时报错:

  1.  update user set password = password(‘new-password’) where user = ‘root’ ;
  2.   
  3.  or
  4.   
  5.  update user set authentication_string= password(‘new-password’) where user = ‘root’ ;

报错原因:mysql5.7.6以后废弃了user表中的password字段和 password() 方法;

所以上面的方法对 mysql8.0.1是行不通的;

2. 根据网友的这篇文章进行修改,报错;

网友文章: 修改MySQL 5.7.9版本的root密码方法以及一些新变化整理

Mysql8 忘记Root密码(转)

3. 参考MYSQL8的官网文档, 感觉写的也很水;

MySQL8官网文档: mysql8.0 reference for manual

Mysql8 忘记Root密码(转)

4. 一定不要采取如下形式该密码:

  1.  use mysql;
  2.  update user set authentication_string=”newpassword” where user=”root”;

这样会给user表中root用户的authentication_string字段下设置了newpassword值;

当再使用ALTER USER ‘root’@’localhost’ IDENTIFITED BY ‘newpassword’时会报错的;

因为authentication_string字段下只能是mysql加密后的41位字符串密码;其他的会报格式错误;

*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,033
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,862