忘记了mysql(5.7)超级用户密码的处理方法一【不需要停止mysql服务】

00:mysql版本及相关实例的配置文件所在路径

[root@temp ~]# mysql -V                     #mysql版本
mysql  Ver 14.14 Distrib 5.7.22, for linux-glibc2.12 (x86_64) using  EditLine wrapper    
[root@temp ~]# tree -L 1 /mysql/data/3306/  #mysql实例相关文件的存放位置
/mysql/data/3306/
├── data
├── exit
├── my.cnf
├── mysqld
├── mysql.pid
├── mysql.sock
└── mysql.sock.lock

1 directory, 6 files

01:我在最开始部署mysql的时候就为自己创建了一个超级用户(用户:chenliang@%   密码:chenliang  权限:all   针对库:*.*   其它:拥有为其它用户分配权限的权限)

mysql> grant all on *.* to 'chenliang'@'%' identified by 'chenliang' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show grants for 'chenliang'@'%';
+------------------------------------------------------------------+
| Grants for chenliang@%                                           |
+------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'chenliang'@'%' WITH GRANT OPTION |
+------------------------------------------------------------------+
1 row in set (0.00 sec

02:现有mysql实例默认的超级用户root@localhost的密码为chenliang,我现在将其修密码修改成123456

mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

03:现有我用root@localhost用户登录,使用原来的密码chenliang,我不知道已修改了密码(模拟哈)

[root@temp 3306]# mysql -uroot -pchenliang -S mysql.sock   #命令行不能暴露密码哈,这里是模拟
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

04:我现有用chenliang@%用户登录,密码为chenliang

[root@temp 3306]# mysql -uchenliang -h127.0.0.1 -pchenliang -P3306  #命令行不能暴露密码哈,这里是模拟
mysql>
mysql> alter user 'root'@'localhost' identified by 'chenliang';     #现在我将root@localhost用户的密码修改成了chenliang哈
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,authentication_string,password_expired from mysql.user where user='root' and host="localhost";
+------+-----------+-------------------------------------------+------------------+
| user | host      | authentication_string                     | password_expired |
+------+-----------+-------------------------------------------+------------------+
| root | localhost | *D072DB593E2E7B068E887A452EB1DB3981A5D844 | N                |
+------+-----------+-------------------------------------------+------------------+
1 row in set (0.00 sec)

mysql> exit
Bye

05:用root@localhost用户登录,密码chenliang,验证是否修改成功

[root@temp 3306]# mysql -uroot -pchenliang -S mysql.sock -e "show databases;"  #命令行不能暴露密码哈,这里是模拟
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

转载于:https://www.cnblogs.com/chenliangc/articles/11590363.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值