MySQL8.0登陆——查看/修改临时密码

一、问题描述

执行以下代码:

mysql -uroot

运行结果如下:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

错误的原因是秘密错误。初次启动Mysql时系统自动生成了临时秘密,找到临时密码就可以正常登陆

二、解决方法

(1)查看临时秘密

1、切换文件目录到 /var/log

cd /var/log

2、查看mysqld.log文件

more mysqld.log

返回结果如下:

2020-07-16T17:07:59.769774Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (my
sqld 8.0.21) initializing of server in progress as process 9857
2020-07-16T17:07:59.776926Z 1 [System] [MY-013576] [InnoDB] InnoDB initializatio
n has started.
2020-07-16T17:08:00.567970Z 1 [System] [MY-013577] [InnoDB] InnoDB initializatio
n has ended.
2020-07-16T17:08:02.500261Z 6 [Note] [MY-010454] [Server] A temporary password i
s generated for root@localhost:YbitKorHK3<T
2020-07-16T17:08:06.605946Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (my
sqld 8.0.21) starting as process 9905
2020-07-16T17:08:06.617260Z 1 [System] [MY-013576] [InnoDB] InnoDB initializatio
n has started.
2020-07-16T17:08:06.806288Z 1 [System] [MY-013577] [InnoDB] InnoDB initializatio
n has ended.
2020-07-16T17:08:06.919836Z 0 [System] [MY-011323] [Server] X Plugin ready for c
onnections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2020-07-16T17:08:07.074850Z 0 [Warning] [MY-010068] [Server] CA certificate ca.p
em is self signed.
2020-07-16T17:08:07.075506Z 0 [System] [MY-013602] [Server] Channel mysql_main c
onfigured to support TLS. Encrypted connections are now supported for this chann
el.
2020-07-16T17:08:07.122128Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: re
ady for connections. Version: '8.0.21'  socket: '/var/lib/mysql/mysql.sock'  por
--More--(21%)

获得临时秘密为:YbitKorHK3<T
输入如下代码登陆mysql的root用户:

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.21

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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 input statement.

在Enter password:后面输入临时秘密即可登陆。

(2)修改初始密码

登陆mysql root用户之后,使用执行以下命令以修改初始密码:

alter  user 'root'@'localhost' identified by "mima@123";
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Little_Yuu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值