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--More--(21%)

获得临时秘密为:YbitKorHK3 输入如下代码登陆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";

你可能感兴趣的:(Linux学习笔记,mysql,linux,centos)