Access denied for user 'root'@'localhost' (using password: YES)
错误位置 FILE: /var/www/html/ThinkPHP/Lib/Core/Db.class.php LINE: 162
紧紧排查问题
# chkconfig --list | grep -i mysql mysqld 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
# ps -ef | grep mysql root 3876 3634 0 10:35 pts/0 00:00:00 grep mysql root 31579 1 0 09:36 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql mysql 31822 31579 0 09:36 ? 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
# service mysqld status mysqld (pid 31822) 正在运行...
显示Mysql运行正常,可就是无法连接数据库,连论坛discuz也同时失去连接。
按照百度的一些网友给出的方案:修改vi /etc/my.cnf配置文件
实际结果:不行,改后无法启动mysql,
# /usr/bin/mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@AY130331113032374e11 ~]# service mysqld start
MySQL Daemon failed to start.
启动 mysqld: [失败]
只好将配置文件又退回去。
再反复试密码:
# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Anyway 都不行
最后的解决办法:修改MySQL 的 root 密码
因为不熟悉linux命令,只好反复摸索,摸索结果在下面红色字符解释。
如果忘记了 MySQL 的 root 密码,可以用以下方法重新设置:
# /etc/init.d/mysqld stop (这一步很关键,之前就是这里没有执行,所以各种通不过)
停止 mysqld:
# service mysqld status
mysqld 已停
[root@localhost bin]# service mysql stop 别处查的资料,这个命令执行不了
Shutting down MySQL
[root@***~]# 150416 12:22:49 mysqld_safe Logging to '/var/log/mysqld.log'.
150416 12:22:49 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
(此步骤,我只执行到这里,网站就已经恢复了)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.5.30-cll MySQL Community Server (GPL) by Atomicorp
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.