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. jquery checkbox全选,全不选,反选方法,jquery checkbox全选只能操作一次

    jquery checkbox全选,全不选,反选方法, jquery checkbox全选只能操作一次, jquery checkbox全选只有第一次成功 >>>>>&g ...

  2. C#.net在后台执行javascript

    string script = string.Format("<script type='text/javascript' >alert('{0}');</script&g ...

  3. 20160515-hibernate--事务

    事务 JDBCTransaction 单个数据库(一个SesisonFactory对应一个数据库),由JDBC实现. Session session = null; Transaction tx =n ...

  4. ClassLoader和Reflect

    什么情况下使用ClassLoader来加载类?其实这个问题应该问,什么时候使用import来加载类,不能使用import的,就只能使用ClassLoader了. 使用import的条件: 1.必须是存 ...

  5. shell中if判断一个变量为空

    1.最直接简单的判断 [ ! $a ] && echo "a is null" 不用那些if语句了,直接缩短代码量. 2. 变量通过" "引号引 ...

  6. cl: cannot open file 'kernel32.lib'

    在测试 jni时, 使用 cl命令, 如 cl -I xx\jdk1.7.0_17\include -I xx\jdk1.7.0_17\include\win32 -LD HelloNative.c ...

  7. selenium简单代码入门

    #!/usr/bin/env python #-*- coding:utf-8 -*- import os,sys,string import time import unittest from se ...

  8. C++ 书籍

    C++ 书籍 一.<深度探索C++对象模型/Inside the C++ Object Model> 二.

  9. Move can only be called on an active agent that has been placed a Navmesh的解决办法

    这是虽然将场景物体添加了Nav Mesh,但是没有进行Bake(烘焙)导致的. 在网上查了 很多久,都没解决这个error,最后发现是因为在unity4.6以下版本中,Bake是Navigation下 ...

  10. frameset,frame应用,常用于后台

    <!DOCTYPE HTML><html><head><title>lin3615</title></head><fram ...