云顶娱乐平台:今日网站突然报错,mysql的故障

修改MySQL密码:复制代码
代码如下:mysqladmin -u root -p password 123456mysqladmin -u用户名
-p旧密码 password 新密码

想在自己的小本上练习一下MySQL,结果登陆就有问题,折腾了半个小时终于搞定,也把这几个常见的问题总结下来和大家分享。笔者的系统是OpenSuSE,其他系统的解决方式类似,供大家参考。

Anyway 都不行

忘记MySQL密码:复制代码 代码如下:chown -R
mysql:mysql /var/lib/mysql/etc/init.d/mysql stop 或 kill -9
杀死进程。[root@corshetlpro01 bin]# cd
/usr/local/mysql/bin./mysqld_safe –user=mysql –skip-grant-tables
–skip-networking & [root@corshetlpro01 bin]# ps -ef | grep mysqlroot
26544 25356 0 15:08 pts/18 00:00:00 /bin/sh ./mysqld_safe –user=mysql
–skip-grant-tables –skip-networkingmysql 26673 26544 0 15:08 pts/18
00:00:00 /usr/local/mysql/libexec/mysqld –basedir=/usr/local/mysql
–datadir=/var/lib/mysql –user=mysql –skip-grant-tables
–skip-networking –log-error=/var/lib/mysql/corshetlpro01.err
–pid-file=/var/lib/mysql/corshetlpro01.pid –socket=/tmp/mysql.sock
–port=3306root 27223 25356 0 15:08 pts/18 00:00:00 grep mysql./mysql -u
rootmysql> use mysql;mysql> update user set password=password
where user=’root’;mysql> flush privileges;mysql> quit#
/etc/init.d/mysql restart# mysql -uroot -penter password:

├ 22000 /bin/sh /usr/bin/mysqld_safe –mysqld=mysqld –user=mysql
–pid-file=/var/run/mysql/mysqld.pid –socket=…  

如果忘记了 MySQL 的 root
密码,可以用以下方法重新设置:

Enter password:     www.2cto.com  

    [root@**~]# mysql -u
root*

想在自己的小本上练习一下MySQL,结果登陆就有问题,折腾了半个小时终于搞定,也把这几个常见的问题总结下来和大家…

     [root@**~]# 150416 12:22:49
mysqld_safe Logging to ‘/var/log/mysqld.log’.
云顶娱乐平台:今日网站突然报错,mysql的故障。     150416 12:22:49 mysqld_safe Starting mysqld daemon with databases
from /var/lib/mysql*

[email protected]:~>
120618 09:40:32 mysqld_safe Logging to ‘/var/log/mysql/mysqld.log’.  

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

root’s password:    www.2cto.com  

    #
mysqld_safe –skip-grant-tables &

atom      1842  0.0  1.0 265564 41296 ?        Sl   09:15   0:00
/usr/sbin/mysqld
–defaults-file=/home/atom/.local/share/akonadi//mysql.conf
–datadir=/home/atom/.local/share/akonadi/db_data/
–socket=/home/atom/.local/share/akonadi/socket-openSuSE.site/mysql.socket
 

   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

但是,查看mysqld的状态,发现Active: inactive (dead)。。。

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

[email protected]:~>
/etc/init.d/mysql status  

Access denied for user ‘root’@’localhost’ (using password: YES)

Process: 21865 ExecStart=/etc/init.d/mysql start (code=exited,
status=0/SUCCESS)  

Oracle is a registered trademark of Oracle
Corporation and/or its
affiliates. Other names may be trademarks
of their respective
owners.

CGroup: name=systemd:/system/mysql.service  

# /usr/bin/mysql
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket
‘/var/lib/mysql/mysql.sock’ (2)

 

按照百度的一些网友给出的方案:修改vi /etc/my.cnf配置文件

那就再启动一次,观察mysql的状态。
 

Copyright (c) 2000, 2013, Oracle and/or
its affiliates. All rights reserved.

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket
‘/var/run/mysql/mysql.sock’ (2)  

[root@AY130331113032374e11 ~]# service mysqld start

[email protected]:~>
mysql -u root -h localhost -p  

紧紧排查问题

[sql]  

Type ‘help;’ or ‘h’ for help. Type ‘c’
to clear the current input statement.

[email protected]:~>
sudo /etc/init.d/mysql restart  

    5.
重新启动MySQL,就可以使用新密码登录了。

atom      1842  0.0  1.0 265564 41296 ?        Sl   09:15   0:00
/usr/sbin/mysqld
–defaults-file=/home/atom/.local/share/akonadi//mysql.conf
–datadir=/home/atom/.local/share/akonadi/db_data/
–socket=/home/atom/.local/share/akonadi/socket-openSuSE.site/mysql.socket
 

    mysql -u root

[plain]  

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

 

 

 

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

MySQL登陆问题总结

最后的解决办法:修改MySQL 的 root 密码

[email protected]:~>
mysql -u root mysql  

 

Loaded: loaded (/etc/init.d/mysql)    www.2cto.com  


  

 

Active: active (running) since Mon, 18 Jun 2012 09:32:43 +0800; 3min 32s
ago  

 

[plain]  

    4. 修改root用户的密码;

mysql> UPDATE user SET Password=PASSWORD(‘xxxx’) where USER=’root’;  

# service mysqld status mysqld (pid 31822) 正在运行…

atom      2788  0.0  0.0   8276   876 pts/0    S+   09:25   0:00 grep
–color=auto mysql  
 

只好将配置文件又退回去。

把PASSWORD(‘xxxx’)中xxxx替换为你自己的密码。重启一次,使用设置的新密码就可以进去了。

# 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)

[plain]  

    mysql -u root -p123456

redirecting to systemctl  


[email protected]:~>
ps aux | grep mysql  

 

[plain]  

   

Loaded: loaded (/etc/init.d/mysql)  

 

这下总算正常了,再尝试登陆又给出错误提示:ERROR 1045 (28000): Access
denied for user ‘root’@’localhost’ (using password: YES)。

   mysql> quit

 

Shutting down MySQL  

atom     22359  0.0  0.0   8276   872 pts/0    S+   09:33   0:00 grep
–color=auto mysql  

 

mysql> quit  

因为不熟悉linux命令,只好反复摸索,摸索结果在下面红色字符解释。

120618 09:40:32 mysqld_safe Starting mysqld daemon with databases from
/var/lib/mysql  

   mysql> update mysql.user set
password=PASSWORD(’123456’) where User=root and
host=’localhost’;

mysql    22322  0.2  1.0 721584 42540 ?        Sl   09:32   0:00
/usr/sbin/mysqld –basedir=/usr –datadir=/var/lib/mysql
–plugin-dir=/usr/lib64/mysql/plugin –user=mysql
–log-error=/var/log/mysql/mysqld.log
–pid-file=/var/run/mysql/mysqld.pid –socket=/var/run/mysql/mysql.sock
–port=3306  

     [1] 16161

└ 22322 /usr/sbin/mysqld –basedir=/usr –datadir=/var/lib/mysql
–plugin-dir=/usr/lib64/mysql/plugin –user=mys…  
 

 

[云顶娱乐平台,email protected]:~>
ps aux | grep mysql  

# chkconfig –list | grep -i mysql mysqld 0:关闭 1:关闭 2:关闭 3:关闭
4:关闭 5:关闭 6:关闭

[email protected]:~>
sudo mysqld_safe –user=mysql –skip-grant-tables –skip-networking &  

实际结果:不行,改后无法启动mysql,

首先,登陆MySQL,提示ERROR 2002 (HY000): Can’t connect to local MySQL
server through socket ‘/var/run/mysql/mysql.sock’
(2),ps后感觉mysqld是启动的呀

错误位置 FILE: /var/www/html/ThinkPHP/Lib/Core/Db.class.php  LINE: 162

[email protected]:~>
/etc/init.d/mysql status  

再反复试密码:

root     22000  0.0  0.0  11536  1644 ?        S    09:32   0:00 /bin/sh
/usr/bin/mysqld_safe –mysqld=mysqld –user=mysql
–pid-file=/var/run/mysql/mysqld.pid –socket=/var/run/mysql/mysql.sock
–datadir=/var/lib/mysql  

 

mysql.service – LSB: Start the MySQL database server  

启动 mysqld: [失败]

CGroup: name=systemd:/system/mysql.service  

显示Mysql运行正常,可就是无法连接数据库,连论坛discuz也同时失去连接。

[email protected]:~>
sudo /etc/init.d/mysql stop  

     mysqld_safe –skip-grant-tables
&

作者 nevasun

 

[1] 22638  

    # service mysqld status
       mysqld 已停

redirecting to systemctl    www.2cto.com  

# 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

 

    2.
用以下命令启动MySQL,以不检查权限的方式启动;(不要修改任何配置文件)

redirecting to systemctl  


Active: inactive (dead)  

    3. 然后用空密码方式使用root用户登录
MySQL;

mysql.service – LSB: Start the MySQL database server  

   mysql> flush privileges;

mysql> FLUSH PRIVILEGES;  

MySQL Daemon failed to start.

redirecting to systemctl  

在网上查到一种解决方案,供大家参考。首先,关闭mysqld服务,然后执行下面两条命令,总算可以进去了,先改密码~