access denied for user 'root'@'localhost' (using password: YES)

来源:互联网 发布:网络安全法 pdf 编辑:程序博客网 时间:2024/05/28 15:07

找了很多资料,都是老版本,全部尝试了一遍,没几个能用的,什么mysqld_safe修改大法等,MYSQL 5.7(平台为CentOS 7 x64)根本就没这个指令

通过自行摸索,终于解决该问题


先定位my.cnf文件

[root@localhost /]# find . -name my.cnf
./etc/my.cnf

# vi ./etc/my.cnf
在[mysqld]栏位末端加入以下参数
skip-grant-tables

然后重启mysql
# systemctl stop mysqld.service
# systemctl start mysqld.service

以上操作后mysql可以正常登陆
# mysql -u root -p
提示输入密码时,直接按回车
[root@localhost php]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.9 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> use mysql

如果root用户已经过期,请启用
mysql> update user set password_expired='N' where user='root';

修改root用户密码 --注意:网上很多都是改password栏位,事实上在5.7里面根本没有这个栏位,密码是记录在authentication_string
mysql> update user set authentication_string=PASSWORD('password') where user='root';

修改完后,到my.cnf文件注释掉skip-grant-tables重启MYSQL后即可

0 0
原创粉丝点击