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. Executor 和Executors

    Java里面线程池的顶级接口是Executor,但是严格意义上讲Executor并不是一个线程池,而只是一个执行线程的工具.真正的线程池接口是ExecutorService. 下面这张图完整描述了线程 ...

  2. [wordpress]后台自定义菜单字段和使用wordpress color picker

    Wordpress Version 4.4.2 参考链接 插件使用wordpress color picker:Add A New Color Picker To WordPress 后台菜单自定义字 ...

  3. glassfish 日志输出配置

    asadmin set-log-levels javax.enterprise.system.tools.deployment=WARNING

  4. Java项目经验

    Java项目经验 转自CSDN. Java就是用来做项目的!Java的主要应用领域就是企业级的项目开发!要想从事企业级的项目开发,你必须掌握如下要点:1.掌握项目开发的基本步骤2.具备极强的面向对象的 ...

  5. 为 Date 对象添加 ago 属性

    /* * 此处,__defineGetter__与__defineSetter__相当于C#实体中类中的get与set **/ Date.prototype.__defineGetter__('ago ...

  6. Mysql 流程控制

    流程控制 分支结构 if分支结构 语法:     if 条件then         -- 语句体     else         -- 缺省语句体     end if; 示例: 循环结构 whi ...

  7. 07_Java8新增的Lambda表达式

    [Lambda表达式概述] Lambda表达式支持将代码块作为方法参数,Lambda表达式允许将使用简洁的代码来创建只有一个抽象方法的接口的实例.(这种接口称为函数式接口) [入门实例] packag ...

  8. iOS中的NSLog的输出格式

    •    %@        对象 •    %d, %i   整数 •    %u         无符整形 •    %f          浮点/双字 •    %x, %X  二进制整数 •  ...

  9. 顺序表 C++模板实现

    #include <iostream> using namespace std; template <typename T> class list{ private: int ...

  10. jquery ajax php 无刷新上传文件 带 遮罩 进度条 效果的哟

    在很多项目中都会叫用户上传东西这些的,自从接触了jquery 和ajax之后就不管做什么,首先都会想到这个,我这个人呢?是比较重视客户体验的,这次我这边负责的是后台板块,然后就有一块是要求用户上传照片 ...