解決Access denied for user 'walter'@'localhost' (using password: YES)

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.


mysql> 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章