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

相关文章

优化MySQL数据库发布系统存储的方法有:1.mysql库主从读写分...
使用mysql的方法:在“我的电脑”→右键→“管理”→“服务”...
在mysql中查看root用户权限的方法:1.命令行启动mysql服务;...
MySQL主从复制是用来备份一个与主数据库一样环境的从数据库,...
运行mysql的方法1.启动mysql服务,在“我的电脑”→右键→“...
开启mysql的方法1.可以通过快捷键win+r,输入cmd,打开窗口,...