安装mysql8.0报错:Access denied for user 'root'@'localhost'

版权声明:转发请标明出处,谢谢! https://blog.csdn.net/Myuhua/article/details/84792121

报错信息:

E:\developsoftware\mysql-8.0.13-winx64\bin>mysql -uroot -p
Enter password: ******
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

E:\developsoftware\mysql-8.0.13-winx64\bin>mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

注意前提,cmd窗口必须以管理员的身份启动!!

报错原因:

1.我在安装mysql8.0的时候用以下的命令进行的初始化。

E:\developsoftware\mysql-8.0.13-winx64\bin>mysqld --initialize-insecure

//用这个命令去做初始化,代表的就是mysql的免密登录。
//而我当时在安装成功后又给它设置了密码,这就导致了一个问题,在连接mysql的时候由于设置了密码,如果不填则会报错;
//如果你填了并且填的跟你设置的是一样的他也会报错,因为你的初始化时用的是免密连接。这样他就出现个死结。。。

2.如果你刚开始不是用的免密连接也报了类似的错误,那么你就去你到mysql的.err文件中下搜索“password”定位后会有密码相关的报错 ,而这个文件就在你设置的mysql数组存储目录下面,比如我设置的位置是E:\developsoftware\data\mysqldata,而在他下面就有一个叫做ZB-PF0S9306.err的错误文件,接下来你打开文件自己定位后看具体原因就可以了。以下是我的.err文件下的信息。

 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! 
                              Please consider switching off the --initialize-insecure option.

解决方法:

1.在初始化的时候使用下面命令,设置默认初始密码:

E:\developsoftware\mysql-8.0.13-winx64\bin>mysqld --initialize
//这个命令会在安装mysql的时候默认给设置一个密码,当然这个密码不是很好记住,
//等后来自己再重新设置一下就行(但是以后连接就需要密码,而不能免密)。

2.将密码设置为空(即不设置密码)。

既然这时候不管有没有密码都不能登入mysql了,那么我们就得想办法先登入进去才能够去将密码设置为空,下面来说跳过权限验证启动mysql服务。

//无需密码启动服务
C:\windows\system32>e:

E:\>cd developsoftware\mysql-8.0.13-winx64\bin

E:\developsoftware\mysql-8.0.13-winx64\bin>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。

E:\developsoftware\mysql-8.0.13-winx64\bin>mysqld --console --skip-grant-tables --shared-memory
2018-12-04T10:47:24.833692Z 0 [System] [MY-010116] [Server] E:\developsoftware\mysql-8.0.13-winx64\bin\mysqld.exe (mysqld 8.0.13) starting as process 11548
2018-12-04T10:47:24.835921Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2018-12-04T10:47:33.022212Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-12-04T10:47:33.158126Z 0 [System] [MY-010931] [Server] E:\developsoftware\mysql-8.0.13-winx64\bin\mysqld.exe: ready for connections. Version: '8.0.13'  socket: ''  port: 0  MySQL Community Server - GPL.
2018-12-04T10:47:33.317040Z 0 [Warning] [MY-011311] [Server] Plugin mysqlx reported: 'All I/O interfaces are disabled, X Protocol won't be accessible'

//重新以管理员身份打开一个cmd窗口,在安全模式下启动mysql服务,然后再修改
E:\developsoftware\mysql-8.0.13-winx64\bin>mysql.exe -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, 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.

mysql>

成功登入mysql服务后,我们将密码设置为“无”就好了(敲黑板:无不是空格!!!!!),这样我们可以在navicat中无需输入密码就可以创建mysql连接。 

mysql> use mysql
Database changed
mysql> update user set authentication_string='' where user='root';
Query OK, 1 row affected (0.39 sec)
mysql> flush privileges
Query OK, 0 rows affected (0.10 sec)

若有问题欢迎大家与我互动交流,如果文章帮到了你,请点小手指。另外,我的博客文章会不定期更新,喜欢的朋友可以加一下关注。

猜你喜欢

转载自blog.csdn.net/Myuhua/article/details/84792121
今日推荐