zoukankan      html  css  js  c++  java
  • 今日网站突然报错,mysql的故障

    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

     

  • 相关阅读:
    《洛谷P2296 寻找道路》
    《浙江科技学院第17届大学生程序设计竞赛:D:合并序列》
    《数论整理二》
    《洛谷P1282 多米诺骨牌》
    《洛谷P2140 小Z的电力管制》
    《洛谷P2798 爆弹虐场》
    Linux下运行C语言程序
    计算圆柱的底面积和体积
    将摄氏温度转化为华氏温度
    如果今天是星期二,那么100天后是星期几?
  • 原文地址:https://www.cnblogs.com/luowei/p/4431958.html
Copyright © 2011-2022 走看看