mysql Access denied for user ‘root’@’localhost’ (using password: YES)解决方法

 更新时间:2015年07月10日 12:02:22   投稿:junjie  
这篇文章主要介绍了mysql Access denied for user ‘root’@’localhost’ (using password: YES)解决方法,本文给出详细的解决步骤及操作注释,需要的朋友可以参考下

今天在启动mysql时出现以下问题:

[root@www ~]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

网上的答案是各种各样的,最终解决问题的方法总结为以下,好多都是没有设置初始密码造成此问题的。

解决方法如下:

[root@www ~]# service mysqld stop   #先关闭mysql服务
Stopping mysqld:                      [ OK ]
[root@www ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@www ~]# mysql -u root -p      #关闭服务后又出现如下问题
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@www ~]# mysql -u root mysql    #键入此命令进入mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, 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> update user set password=password('123') where user='root' and host='localhost';  ---->修改root的密码
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush priviledge;
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 'priviledge' at line 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
[root@www ~]# mysql -u root -p           ------>重新进入
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, 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> \q
Bye

到此就完了!!

相关文章

  • MySQL为何不建议使用默认值为null列

    MySQL为何不建议使用默认值为null列

    本文主要介绍了MySQL为何不建议使用默认值为null列,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-08-08
  • MySQL 存储过程中执行动态SQL语句的方法

    MySQL 存储过程中执行动态SQL语句的方法

    这篇文章主要介绍了MySQL 存储过程中执行动态SQL语句的方法,需要的朋友可以参考下
    2014-08-08
  • MySQL事务控制流与ACID特性

    MySQL事务控制流与ACID特性

    本文将会介绍 MySQL 的事务 ACID 特性和 MySQL 事务控制流程的语法,并介绍事务并发处理中可能出现的异常情况,比如脏读、幻读、不可重复读等等,最后介绍事务隔离级别。感兴的小伙伴可以一起来学习
    2021-08-08
  • MySQL数据库如何导入导出(备份还原)

    MySQL数据库如何导入导出(备份还原)

    这篇文章主要介绍了MySQL数据库如何导入导出(备份还原),需要的朋友可以参考下
    2015-10-10
  • mysql8.0 用户角色管理及授权的实现

    mysql8.0 用户角色管理及授权的实现

    MySQL是一种常见的关系型数据库管理系统,它提供了强大的安全机制来管理用户权限,本文主要介绍了mysql8.0 用户角色管理及授权的实现,具有一定的参考价值,感兴趣的可以了解一下
    2024-04-04
  • mysql 5.6.23 winx64.zip安装详细教程

    mysql 5.6.23 winx64.zip安装详细教程

    这篇文章主要介绍了mysql 5.6.23 winx64.zip安装详细教程,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2017-02-02
  • MySQL超详细实现用户管理实例

    MySQL超详细实现用户管理实例

    MySQL 是一个多用户数据库,具有功能强大的访问控制系统,可以为不同用户指定不同权限。在前面的章节中我们使用的是 root 用户,该用户是超级管理员,拥有所有权限,包括创建用户、删除用户和修改用户密码等管理权限
    2022-06-06
  • mysql source 命令导入大的sql文件的方法

    mysql source 命令导入大的sql文件的方法

    本文将详细介绍mysql source 命令导入大的sql文件的方法;需要的朋友可以参考下
    2012-11-11
  • Mysql误删数据解决方案及kill语句原理

    Mysql误删数据解决方案及kill语句原理

    这篇文章主要介绍了Mysql误删数据解决方案及kill语句原理,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-09-09
  • MySQL主从同步延迟的原因及解决办法

    MySQL主从同步延迟的原因及解决办法

    今天小编就为大家分享一篇关于MySQL主从同步延迟的原因及解决办法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-03-03

最新评论