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

所属分类: 数据库 / Mysql 阅读数: 369
收藏 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

到此就完了!!

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

mysql 5.7.20解压版安装方法步骤详解(两种方法)

本文给大家分享mysql 5.7.20解压版安装方法步骤详解,本文给大家分享两种方法,非常不错,具有参考借鉴价值,需要的朋友参考下吧
收藏 0 赞 0 分享

MySql 5.7.20安装及data和my.ini文件的配置

本文通过图文并茂的形式给大家介绍了MySql 5.7.20安装及data和my.ini文件的配置方法,本文给大家介绍的非常详细,需要的朋友参考下吧
收藏 0 赞 0 分享

安装mysq 5.7.20 解压版遇到的坑(推荐)

最近有朋友说当mysql5.7.20解压版环境变量配置好后,根目录没有my.ini 也没有 my-default.ini文件,怎么处理这个问题呢,下面小编给大家带来了解决方案,大家可以参考下
收藏 0 赞 0 分享

Mac系统下MySql下载MySQL5.7及详细安装图解

这篇文章主要介绍了Mac系统下MySql下载MySQL5.7及详细安装图解,本文图文并茂给大家介绍的非常详细,需要的朋友可以参考下
收藏 0 赞 0 分享

mysql千万级数据分页查询性能优化

本文给大家分享的是作者在使用mysql进行千万级数据量分页查询的时候进行性能优化的方法,非常不错的一篇文章,对我们学习mysql性能优化非常有帮助
收藏 0 赞 0 分享

RedHat6.5/CentOS6.5安装Mysql5.7.20的教程详解

这篇文章主要介绍了RedHat6.5/CentOS6.5安装Mysql5.7.20的教程详解,非常不错,具有参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

MAC下MYSQL数据库密码忘记的解决办法

这篇文章主要介绍了Mac操作系统下MYSQL数据库密码忘记的快速解决办法,教大家重置MYSQ密码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

ubuntu下mysql版本升级到5.7

这篇文章主要为大家详细介绍了ubuntu下mysql版本升级到5.7的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Mysql触发器在PHP项目中用来做信息备份、恢复和清空

这篇文章主要介绍了Mysql触发器在PHP项目中用来做信息备份、恢复和清空的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

MySql数据库查询中的特殊命令

本文给大家介绍了MySql数据库查询中的特殊命令,包括mysql的安装,特殊查询语句,非常不错,具有参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多