linux mysql8 忘记密码

阅读: 评论:0

linux mysql8 忘记密码

linux mysql8 忘记密码

文章目录

      • 1、关闭mysql登录验证
      • 2、重置mysql密码
      • 3、开启mysql登录验证
      • 4、修改mysql密码


1、关闭mysql登录验证


停止mysql

$ systemctl stop mysqld.service

修改/etc/myf,跳过权限验证

在myf 下面添加

skip-grant-tables

启动mysql

$ systemctl start mysqld.service

2、重置mysql密码


使用下面命令登录,无密码进入mysql命令行 ```shell $ mysql -u root ```

重置root密码为空

update user set authentication_string='' where user='root';

查看root密码是否为空

select user, authentication_string from mysql.user;

保存修改

flush privileges;

示例如下:

$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 7
Server version: 8.0.32 Source distributionCopyright (c) 2000, 2023, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or 'h' for help. Type 'c' to clear the current sql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set authentication_string='' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0mysql> select user, authentication_string from mysql.user;
+------------------+------------------------------------------------------------------------+
| user             | authentication_string                                                  |
+------------------+------------------------------------------------------------------------+
| root             |                                                                        |
| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
+------------------+------------------------------------------------------------------------+
6 rows in set (0.01 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql> q
Bye

3、开启mysql登录验证


停止mysql

$ systemctl stop mysqld.service

修改/etc/myf,把myf 下面添加的skip-grant-tables删除

启动mysql

$ systemctl start mysqld.service

4、修改mysql密码


使用下面命令登录,在输入密码的那一步直接回车

$ mysql -uroot -p

修改root密码
‘root’@‘%’: root可以允许任务机器连接

alter user 'root'@'%' identified by '你的密码';

查看root密码

select user, authentication_string from mysql.user;

保存修改

flush privileges;

示例如下:

$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 8
Server version: 8.0.32 Source distributionCopyright (c) 2000, 2023, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or 'h' for help. Type 'c' to clear the current sql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> alter user 'root'@'%' identified by &#_2023';
Query OK, 0 rows affected (0.00 sec)mysql> select user, authentication_string from mysql.user;
+------------------+------------------------------------------------------------------------+
| user             | authentication_string                                                  |
+------------------+------------------------------------------------------------------------+
| root             | *A780CA81542274F7A6F52BBC40B7B2E2F9BE8A0F                              |
| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
+------------------+------------------------------------------------------------------------+
6 rows in set (0.01 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql> q
Bye

本文发布于:2024-01-30 04:31:28,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170656029219235.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:忘记密码   linux
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23