微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Mysql 5.7 CentOS Access denied for user 'root'@'localhost'解决方式

在centOS上安装完mysql, 登录MysqL时遇到错误
[root@MysqL-server Downloads]# MysqL -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

关键要用MysqLD_OPTS="--skip-grant-tables"重新启动MysqL服务
[root@MysqL-server Downloads]# systemctl stop MysqLd
[root@MysqL-server Downloads]# systemctl set-enviroment MysqLD_OPTS="--skip-grant-tables"
UnkNown operation 'set-enviroment'.
[root@MysqL-server Downloads]# systemctl set-environment MysqLD_OPTS="--skip-grant-tables"
[root@MysqL-server Downloads]# systemctl start MysqLd
[root@MysqL-server Downloads]# myslq -u root
bash: myslq: command not found...
Similar command is: 'MysqL'
[root@MysqL-server Downloads]# MysqL -u root
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 3
Server version: 5.7.18 MysqL Community Server (GPL)

copyright (c) 2000, 2017, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| MysqL              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.06 sec)

MysqL> use MysqL
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MysqL> update user set authentication_string=password('root') where user = 'root';
Query OK, 1 row affected, 1 warning (0.07 sec)
Rows matched: 1  Changed: 1  Warnings: 1

MysqL> flush previleges;
ERROR 1064 (42000): You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near 'previleges' at line 1
MysqL> flush priviledges;
ERROR 1064 (42000): You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near 'priviledges' at line 1
MysqL> flush privileges;
Query OK, 0 rows affected (0.11 sec)

MysqL> quit
Bye
[root@MysqL-server Downloads]# systemctl stop MysqLd
[root@MysqL-server Downloads]# systemctl unset-environment MysqLD_OPTS
[root@MysqL-server Downloads]# systemctl start MysqLd
[root@MysqL-server Downloads]# 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.18

copyright (c) 2000, 2017, 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>


参考:https://stackoverflow.com/questions/33510184/change-MysqL-root-password-on-centos7

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐