温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mysql8.0忘记密码如何找回

发布时间:2020-08-13 01:52:15 来源:网络 阅读:413 作者:wjw555 栏目:系统运维

为了演示,找个测试环境来操作,千万不要线上这么搞
pkill mysqld 关闭掉mysql

跳过MySQL的权限表启动MySQL服务:
--skip-grant-tables启动mysql

/usr/local/mysql8013/bin/mysqld_safe --defaults-file=/data/mysql8/my8.cnf --skip-grant-tables & 

将密码置空:

root@localhost [(none)]>update mysql.user set authentication_string='' where user="root" and host="localhost";
Query OK, 1 row affected (0.06 sec)
Rows matched: 1  Changed: 1  Warnings: 0

root@localhost [(none)]>

pkill mysqld 关闭掉mysql

再次启动mysql服务

[root@localhost ~]# /usr/local/mysql8013/bin/mysqld --defaults-file=/data/mysql8/my8.cnf &

无密码登录MySQL服务并设置新的密码:


root@localhost [(none)]>select version();
+-----------+
| version() |
+-----------+
| 8.0.13    |
+-----------+
root@localhost [(none)]>alter user user() identified by 'jist558@wei';

[root@localhost ~]# mysql -uroot -p'jist558@wei' -e "select version();"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+
| version() |
+-----------+
| 8.0.13 |
+-----------+

密码写入.my.cnf文件就可以mysql直接登录mysql窗口:

[root@localhost ~]# cat .my.cnf 
[mysql]
prompt="\u@\h:\p \R:\m:\s[\d]>"
no-auto-rehash
user=root
password=jist558@wei
[root@localhost ~]# mysql -e "select version();"
+-----------+
| version() |
+-----------+
| 8.0.13    |
+-----------+

演示完毕

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI