返回顶部
首页 > 资讯 > 数据库 >Mysql 5.7 CentOS Access denied for user 'root'@'localhost'解决方式
  • 455
分享到

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

2024-04-02 19:04:59 455人浏览 泡泡鱼
摘要

在Centos上安装完Mysql, 登录mysql时遇到错误 [root@mysql-server Downloads]# mysql -u root ERROR 1045 (28000): Access

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
您可能感兴趣的文档:

--结束END--

本文标题: Mysql 5.7 CentOS Access denied for user 'root'@'localhost'解决方式

本文链接: https://lsjlt.com/news/46521.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作