ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

root@mysql ~]# mysql -p -u root

Enter password: 

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决

参考

Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'

Ubuntu8.04刚装了mysql

sudo apt-get install mysql

安装成功了,安装最后要求输入了密码,也输入了,OK

mysql -uroot -p

输入设置的密码

竟然报错了!

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YSE)

问朋友,他说初始密码是空的,可我命名设置了密码的阿。

密码留空

还是错误!

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

于是重改密码!

# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

# /etc/init.d/mysqld restart
# mysql -uroot -p
Enter password: 

mysql>

 

完整过程解决 ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using
password: NO)

 ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: NO)
此问题网上大部分都是围绕下面的第二步(修改密码)展开的,很是坑爹的是我怎么都登陆不进去(各种模式登陆均失败),何谈修改密码呢?
本人分心mysql日志文件总结此问题的整体步骤如下:

第一步:修改pid路径
查看日志文件:
 cat /var/log/mysqld.log

2013-10-26 16:39:34 3712 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
2013-10-26 16:39:34 3712 [ERROR] Can't start server: can't create PID file: No such file or directory

原因:
mysql 用户没有操作/var/run目录的权限,所以pid文件无法创建,导致登陆时无法建立 进程信息文件,登陆进程就无法开启,自然无法登陆。

解决:
修改 /etc/my.conf
原来的
 #pid-file=/var/run/mysqld/mysqld.pid
修改为
pid-file=/var/lib/mysql/mysqlid.pid

检查发现,mysql用户根本无法 cd /var/run/。修改为mysql可以有权限的目录后再执行mysql就进入数据库了。

第二步:修改数据库默认密码
/etc/init.d/mysql stop   (service mysqld stop )
/usr/bin/mysqld_safe --skip-grant-tables
另外开个SSH连接
[root@localhost ~]# mysql
mysql>use mysql
mysql>update user set password=password("123456") where user="root";
mysql>flush privileges;
mysql>exit

然后
[mysql@localhost etc]$ ps -A | grep mysql
4532 pts/0    00:00:00 mysqld_safe
5542 pts/0    00:00:00 mysqld
[mysql@localhost etc]$ kill -9 4532 5542 
正常启动 MySQL:/etc/init.d/mysql start   (service mysqld start)

第三步:
登陆ok。 mysql -uroot -p

/*********************下面为本人的完整修复过程信息,含分析过程:*******************************/
myslq status SUCCESS 但是各种尝试登陆均不起效
[mysql@localhost etc]$ service mysql start
Starting MySQL. SUCCESS!
[mysql@localhost etc]$ service mysql status
SUCCESS! MySQL running (4463)
[mysql@localhost etc]$ mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[mysql@localhost etc]$ mysql -umysql
ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: NO)
[mysql@localhost etc]$ mysqladmin -uroot -p password
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
想死有木有!!!
冷静查看日志吧-->
[mysql@localhost ~]$ cat /var/log/mysqld.log 
2013-10-26 16:39:34 3712 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
2013-10-26 16:39:34 3712 [ERROR] Can't start server: can't create PID file: No such file or directory
尼玛!!!
[mysql@localhost ~]$ cd /var/run/
-bash: cd: /var/run/: 权限不够
[mysql@localhost ~]$ 
就这样吧!!!
[mysql@localhost ~]$ cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid
pid-file=/var/lib/mysql/mysqlid.pid
重启mysql
[mysql@localhost etc]$ service mysql stop
Shutting down MySQL.. SUCCESS!
[mysql@localhost etc]$ service mysql start
Starting MySQL.. SUCCESS!
尼玛啊!!!
[mysql@localhost etc]$ mysql
ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: NO)
到这一步,如果想执行mysql直接登陆,需要如下操作
[mysql@localhost etc]$ service mysql stop
Shutting down MySQL.. SUCCESS! 
[mysql@localhost etc]$ mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[mysql@localhost ~]$ mysql
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.14

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> 

但是要想在service mysql start方式下登陆继续往下看吧。
尼玛!!!
[mysql@localhost etc]$ mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[mysql@localhost ~]$ mysql
ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: NO)
解释:这里是因为数据库默认的root密码没有设置导致的。
(下面这个是网络上搜索ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: NO)  大家的解决方法,但是如果
没有修改pid的路径,这里根本登陆不进去,何谈修改密码。因为mysql始终无法创建pid文件才是问题根源)
这种问题需要强行重新修改密码,方法如下:
/etc/init.d/mysql stop   (service mysqld stop )
/usr/bin/mysqld_safe --skip-grant-tables
另外开个SSH连接
[root@localhost ~]# mysql
mysql>use mysql
mysql>update user set password=password("123456") where user="root";
mysql>flush privileges;
mysql>exit

然后
[mysql@localhost etc]$ ps -A | grep mysql
4532 pts/0    00:00:00 mysqld_safe
5542 pts/0    00:00:00 mysqld
[mysql@localhost etc]$ kill -9 4532 5542 
正常启动 MySQL:/etc/init.d/mysql start   (service mysqld start)

终于!!!
[mysql@localhost ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.14

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.

 

Red Hat Enterprise Linux 5服务器上mysql启动报错:ERROR 1045 (28000):
Access denied for user 'root'@'localhost' (using password: NO)
原因1-启动命令错误:
我开始的时候直接输入命令:mysql start 
正确的启动命令是:

/etc/rc.d/init.d/mysql start

原因2-配置文件错误:
检查etc下面的my.cnf如下内容:

[client]
#password   = your_password
port     = 3306
socket     = /usr/mysql-data/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port     = 3306
socket     = /usr/mysql-data/mysql.sock

原因3-启动文件错误:
需要修改MySQL启动脚本/etc/rc.d/init.d/mysql,
其中datadir=   ?     一行检查下!

原因4-前提是你在使用php连接时候报错!
在/etc/php.ini修改mysql.default_socket的值设置为:
mysql.default_socket=/var/lib/mysql/mysql.sock
回到终点设置个连接:ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
(在/etc/php.ini中mysql.default_socket这个文件中,关于mysql.default_socket的值的说明是这样的,
;Default socket name for local MySQL connects. If empty, uses the built-in MySQL defaults.
这个值一开始是空的,也就是说,如果我们不主动去修改的话,php将会使用内建在mysql中的默认值)

 

另一篇文章:

Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'问题的解决

这种问题需要强行重新修改密码,方法如下:

/etc/init.d/mysql stop   (service mysqld stop )
/usr/bin/mysqld_safe --skip-grant-tables
另外开个SSH连接
[root@localhost ~]# mysql
mysql>use mysql
mysql>update user set password=password("123456") where user="root";
mysql>flush privileges;
mysql>exit

pkill -KILL -t pts/0 可将pts为0的**用户(之前运行mysqld_safe的用户窗口)强制踢出
正常启动 MySQL:/etc/init.d/mysql start   (service mysqld start)

注意:另外还遇到需要service mysql star才能启动service mysql stop才能停止。
还有直接使用mysql不能找到命令,错误为“bash: mysql: command not found”可以直接**mysql的安装目录中的bin文件夹跟绝对路径运行命令,还有的需要加./mysql
才能执行。

 

本文来自:http://sundful.javaeye.com/blog/704337

 

另一篇关于清除密码、重置用户的文章:

 

Quote:

First things first. Log in as root and stop the mysql daemon. 

sudo /etc/init.d/mysql stop
 

Now lets start up the mysql daemon and skip the grant tables which store the passwords.

sudo mysqld_safe --skip-grant-tables&

(press Ctrl+C now to disown the process and start typing commands again)

You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.

sudo mysql --user=root mysql

update user set Password=PASSWORD('new-password');
flush privileges;
exit;
 

Now kill your running mysqld then restart it normally. 

sudo killall mysqld_safe&
(press Ctrl+C now to disown the process and start typing commands again)
/etc/init.d/mysql start

You should be good to go. Try not to forget your password again.

http://www.howtoforge.com/reset-forgotten-mysql-root-password

 

 

另外关于denied的总结:

MySQL Authentication Denial

3/29/2005, 12:05 am

It seems to me that a lot of people have auth denial when trying to make connections to MySQL. They seem to ignore the text of the error message. ‘Access Denied’ means access denied, nothing else.

Remember three things have to match. The host as MySQL sees it, the username, and the password. When MySQL returns access denied it’s not broken. One or more of those three things does not match. I don’t really
need to reiterate what’s in the manual. Chang the lock or change the key to make it fit.

其中连接到mysql的文档内容为:

http://dev.mysql.com/doc/refman/5.5/en/access-denied.htm

时间: 2025-01-02 03:11:30

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)的相关文章

mysql全局权限账户%登录不上ERROR 1045 (28000): Access denied for user 'mhz'@'localhost' (using password: YES)

mysql全局权限账户%登录不上 ERROR 1045 (28000): Access denied for user 'mhz'@'localhost' (using password: YES)  解决 查看错误提示  有主机名字的就必须赋值主机名 mysql> GRANT ALL PRIVILEGES ON *.* TO 'mhz'@'mgr2' IDENTIFIED BY 'mhz' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 s

ERROR 1045 (28000): Access denied for user 'axt'@'localhost' (using pass

ERROR 1045 (28000): Access denied for user 'axt'@'localhost' (using password: YES)解决 环境:MySQL Sever 5.1 + MySQL命令行工具 问题:MySQL用户远程登录遇到此问题:ERROR 1045 (28000): Access denied for user 'axt'@'localhost' (usingpassword: YES). 如图: 解决: 新创建的用户不能立即失效,执行以下命令后重启

MySQL中出现连接错误:ERROR 1045 (28000): Access denied for user

  MySQL中出现连接错误: ERROR 1045 (28000): Access denied for user ---------------------------------------------------------------------------------- 1.添加用户 shell>mysql mysql>use mysql mysql>grant all privileges on *.* to 'test' identified by 'test' with

ERROR 1045 (28000): Access denied for user 'root'@'localhost' 的解决方法

风信网(ithov.com)原创文章:今天在测试一款bacula开源备份软件的时候,需要使用到mysql数据库,当运行以下命令时报错误如下: [root@localhost etc]# ./grant_mysql_privileges ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) Error creating privileges. 登陆到msyql中去解决该问题: [root

MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)的真正原因

在博客Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)里 面,我介绍了一下安装MySQL后登陆MySQL时会遇到ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 这个错误,当时不知道真正的原因,搜索了一些网上的资料,测试验证了如何解决

Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

案例环境:              操作系统 :Red Hat Enterprise Linux Server release 5.7 (Tikanga) 64 bit           数据库版本 : Mysql 5.6.19 64 bit 案例介绍: 今 天开始学习mysql,遂先安装了Mysql 5.6.19 64bit 版本的数据库,结果安装成功了,但是使用root登录时遇到了ERROR 1045 (28000): Access denied for user 'root'@'loc

【技术贴】解决Mysql ERROR 1045 (28000): Access denied for

  今天Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' 肯定是密码不对了.那么重置一下密码吧.   打开 cmd 输入以下四个步骤:   1.mysql -u root mysql (登陆mysql.如果你没有在环境变量path里面加入bin路径,建议你直接去mysql的bin目录下运行此命令) 2. UPDATE user SET Password=PASSWORD('123456') where USER

解决mariadb grant ERROR 1045 (28000): Access denied for user

用mariadb也有一段时间了,常用命令和语法,基本没变.比较复杂一点的,例如replication,也没有发现根mysql有什么不同的地方. 不过,今天真发现有不同的地方了,mariadb的权限管理根mysql不一样,mysql可以创建一个根root账户同等权限的账户,但是mariadb就不行了,写法上也所不同. 1,mariadb  grant授权报错    MariaDB [(none)]> grant all privileges on *.* TO tank@'192.168.%' I

MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 的原因分解决办法_Mysql

MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 的解决办法和原因 这两天下载了MySQL5.7.11进行安装,发现到了初次使用输入密码的时候,不管怎样都进不去,即使按照网上说的在mysqld 下面添加skip-grant-tables也是不行,后来研究了两天,终于找出原因和解决办法. 复制代码 代码如下: [mysqlld] skip-grant-tables: 原因