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 密码,可以用以下方法重新设置:

    1. KILL掉系统里的MySQL进程;  

# /etc/init.d/mysqld stop  (这一步很关键,之前就是这里没有执行,所以各种通不过)
     停止 mysqld:

# service mysqld status
       mysqld 已停

[root@localhost bin]# service mysql stop   别处查的资料,这个命令执行不了

Shutting down MySQL

 
    2. 用以下命令启动MySQL,以不检查权限的方式启动;(不要修改任何配置文件)
     mysqld_safe --skip-grant-tables &
 
    # mysqld_safe --skip-grant-tables &
     [1] 16161

     [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

     (此步骤,我只执行到这里,网站就已经恢复了)

    3. 然后用空密码方式使用root用户登录 MySQL;
    mysql -u root
    [root@***~]# mysql -u root

   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.

    4. 修改root用户的密码;
   
   mysql> update mysql.user set password=PASSWORD('123456') where User=root and host='localhost';
   mysql> flush privileges;
   mysql> quit
 
    5. 重新启动MySQL,就可以使用新密码登录了。
    mysql -u root -p123456

今日网站突然报错,mysql的故障的更多相关文章

  1. mysql启动报错 mysql InnoDB: Error: could not open single-table tablespace file

    mysql启动不成功,报错 mysql InnoDB: Error: could not open single-table tablespace file innodb_force_recovery ...

  2. mysql 数据传输报错 MySQL server has gone away With statement:

    利用navicat premium 拷贝数据库时,报错MySQL server has gone away With statement:, 造成这样的原因一般是sql操作的时间过长,或者是传送的数据 ...

  3. 【生产问题】-dbcc checkdb报错-数据页故障

    更多操作参考:https://www.cnblogs.com/gered/p/9435282.html [生产问题]-dbcc checkdb报错-数据页故障 数据页故障,索引页故障 use db_t ...

  4. MySQL Insert数据量过大导致报错 MySQL server has gone away

    接手了同事的项目,其中有一个功能是保存邮件模板(包含图片),同事之前的做法是把图片进行base64编码然后存在mysql数据库中(字段类型为mediumtext)然后保存三张图片(大概400k)的时候 ...

  5. MYSQL导入数据报错|MYSQL导入超大文件报错|MYSQL导入大数据库报错:2006 - MySQL server has gone away

    导SQL数据库结构+数据时,如果数据是批量插入的话会报错:2006 - MySQL server has gone away. 解决办法:找到你的mysql目录下的my.ini配置文件(如果安装目录没 ...

  6. mysql 有没有参数都报错“mysql: unknown option”

    报错: [root@XXXX tmp]# mysql -uroot -pmysql: unknown option '--You have new mail in /var/spool/mail/ro ...

  7. linux 报错Mysql.pid 文件不存在导致service Mysqld start 失败

    Mysql.pid 文件不存在导致service Mysqld start 失败 1.  到提示报错的mysql.pid 不存在的目录下  使用 touch 命令创建mysql.pid文件.    t ...

  8. ubuntu安装了mysql 但是编译报错 mysql.h: No such file or directory

    在Ubuntu体系中,已经安装了mysql,即应用sudo apt-get install mysql-server mysql-client 但是用C编译mysql数据库时,报错fatal erro ...

  9. linux定时任务报错mysql: command not found

    本人在用docker做镜像的时候,把定时任务打到镜像里,但是执行的时候发现错误日志总是报 sh: mysql: command not found ,然后开始解决问题 1)首先确认镜像有没有装mysq ...

随机推荐

  1. 灯笼Lantern下载及使用教程

    http://www.iyaxi.com/2015-11-17/732.html 最新科学上网QQ群群号:465166189点击链接加入群[翻越长城三群]:http://jq.qq.com/?_wv= ...

  2. WordPress 后台提示输入FTP信息

    Wordpress 安裝主題時,需要輸入ftp訊息 參考了:WordPress后台更新提示输入FTP信息 ,解決方法是: 方法一.通過ssh 對wordpress 項目的文件夾賦權限 sudo cho ...

  3. C#控制台输入

    学习C语言后,在学习C#会有一个很不适应的小毛病.那就是在C语言里面你可以在一行输入好几个数字或是字母然后分别赋给相应的变量.可是在C#里面就不一样了,它只能读取一行.要实现一个一个变量赋值那就只有一 ...

  4. PHP之数组函数归类

    数组之所以强大,除了本身声明.存储方式灵活,它还有坚强后盾:一系列功能各异的数组处理函数.就像一只军队,除了领队将军本身能征善战,指挥英明之外,还有一群不怕死.忠实于他的士兵,这样才能显得整体的强大. ...

  5. Python(2.7.6) 标准日志模块 - Logging Handler

    Python 标准日志模块使用 Handler 控制日志消息写到不同的目的地,如文件.流.邮件.socket 等.除了StreamHandler. FileHandler 和 NullHandler ...

  6. ubuntu修改grub背景

    grub背景由/etc/grub.d/05_debian_theme定义,修改图片只需要将图片文件放到/boot/grub,d/下即可, 修改颜色只需编辑/boot/grub.d/grub.cfg

  7. 利用Ajax改变发送请求方式

    由于测试的时候需要模拟Head请求,解决办法:先访问要请求的站点,然后在浏览器的控制台下执行如下代码,请求方式就为参数给的值: var xmlHttp; if (window.ActiveXObjec ...

  8. jQuery 源码分析 7: sizzle

    jQuery使用的是sizzle这个选择器引擎,这个引擎以其高速著称,其实现十分精妙但是也足够复杂,下面现简单分析一下相关的代码. 在jQuery的部分API接口是直接引用了Sizzle的方法,这些接 ...

  9. android中的4种点击事件

    四种点击事件     (1)采用内部类的方式去实现OnClickListener      (2)匿名内部类     (3)当前类imp OnClickListener      (4)onclick ...

  10. WinForm应用程序退出的方法

    this.Close(); 只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出. Application.Exit(); 强制所有消息中止,退出所有的 ...