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

所属分类: 数据库 / Mysql 阅读数: 374
收藏 0 赞 0 分享

今天在启动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

到此就完了!!

更多精彩内容其他人还在看

使用FriendFeed来提升MySQL性能的方法

这篇文章主要介绍了使用FriendFeed来提升MySQL性能的方法,用其来存储无模式的数据从而能够维护索引,需要的朋友可以参考下
收藏 0 赞 0 分享

浅谈InnoDB隔离模式的使用对MySQL性能造成的影响

这篇文章主要介绍了InnoDB隔离模式的使用对MySQL性能造成的影响,作为基于MySQL的最出名的数据库,InnoDB相关的性能问题一直是DBA关注的热点,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL中修改表结构时需要注意的一些地方

这篇文章主要介绍了MySQL中修改表结构时需要注意的一些地方,作者援引Percona的相关的说明来讲述如何避免相关操作导致表无法使用的问题,一些需要的朋友可以参考下
收藏 0 赞 0 分享

使用cgroups来限制MySQL企业备份服务对资源的占用

这篇文章主要介绍了使用cgroups来限制MySQL企业备份服务对资源的占用,以限制mysqlbackup相关的进程和线程对CPU和内存的闲时消耗,需要的朋友可以参考下
收藏 0 赞 0 分享

详细讲解安全升级MySQL的方法

这篇文章主要介绍了详细讲解安全升级MySQL的方法,在此特别推荐使用Percona Toolkit来辅助升级,当然,本文示例基于Linux环境,需要的朋友可以参考下
收藏 0 赞 0 分享

大幅提升MySQL中InnoDB的全表扫描速度的方法

这篇文章主要介绍了大幅提升MySQL中InnoDB的全表扫描速度的方法,作者谈到了预读取和多次async I/O请求等方法,减小InnoDB对MySQL速度的影响,需要的朋友可以参考下
收藏 0 赞 0 分享

大幅优化MySQL查询性能的奇技淫巧

这篇文章主要介绍了大幅优化MySQL查询性能的方法,作者根据实际运行时间比对分析了InnoDB等几个重要的MySQL性能优化点,极力推荐!需要的朋友可以参考下
收藏 0 赞 0 分享

12个优化MySQL的技巧小整理

这篇文章主要介绍了12个优化MySQL的技巧小整理,包括表连接和WHERE语句等基本的优化点等内容,已经了解的也不妨加深一下印象,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL结合使用数据库分析工具SchemaSpy的方法

这篇文章主要介绍了MySQL结合使用数据库分析工具SchemaSpy的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

在VB.NET应用中使用MySQL的方法

这篇文章主要介绍了在VB.NET应用中使用MySQL的方法,操作基于Visual Studio IDE进行,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多