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

所属分类: 数据库 / Mysql 阅读数: 371
收藏 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 数据库更新错误的解决方法

Mysql 数据库更新错误的解决方法,需要的朋友可以参考下。
收藏 0 赞 0 分享

mysql主从库不同步问题解决方法

本来配置可以使用的mysql主从库同步的数据库,突然出现无法同步的情况。那么大家可以参考下面的方法解决下。
收藏 0 赞 0 分享

解决mysql ERROR 1017:Can't find file: '/xxx.frm' 错误

如果重启服务器前没有关闭mysql,MySql的MyiSAM表很有可能会出现 ERROR #1017 :Can't find file: '/xxx.frm' 的错误
收藏 0 赞 0 分享

linux忘记mysql密码处理方法

这篇文章主要为大家介绍下linux忘记mysql密码处理方法,需要的朋友可以参考下。
收藏 0 赞 0 分享

MySQL 重装MySQL后, mysql服务无法启动

把mysql程序卸载后, 重装, 结果mysql服务启动不了,碰到这个问题的朋友可以参考下。
收藏 0 赞 0 分享

RedHat下MySQL的基本使用方法分享

RedHat 下MySQL安装,简单设置以用基本的使用方法,需要的朋友可以参考下。
收藏 0 赞 0 分享

mysql千万级数据大表该如何优化?

如何设计或优化千万级别的大表?此外无其他信息,个人觉得这个话题有点范,就只好简单说下该如何做,对于一个存储设计,必须考虑业务特点,收集的信息如下
收藏 0 赞 0 分享

彻底卸载MySQL的方法分享

由于安装MySQL的时候,疏忽没有选择底层编码方式,采用默认的ASCII的编码格式,于是接二连三的中文转换问题随之而来,就想卸载了重新安装MYSQL,这一卸载倒是出了问题,导致安装的时候安装不上,在网上找了一个多小时也没解决。
收藏 0 赞 0 分享

MySQL数据表字段内容的批量修改、清空、复制等更新命令

MySQL数据表字段内容的批量修改、清空、复制等更新命令,需要的朋友可以参考下。
收藏 0 赞 0 分享

MySQL SHOW 命令的使用介绍

MySQL SHOW 命令的使用介绍,使用mysql的朋友可以参考下。
收藏 0 赞 0 分享
查看更多