返回
基础
分类

首先发现/tmp/mysql.sock不存在,mysqladmin修改密码失败

日期: 2020-01-02 07:52 浏览次数 : 74

mysql启动错误

[[email protected] itcast]# /etc/init.d/mysql restart //启动服务

ERROR! MySQL server PID file could not be found!
Starting MySQL................ ERROR! The server quit without updating PID file (/var/lib/mysql/itcast02.pid).//出错

[[email protected] itcast]#mysql -u root -p //登录

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) //错误

[[email protected] itcast]# /etc/rc.d/init.d/mysqld status //查看状态失败

bash: /etc/rc.d/init.d/mysqld: No such file or directory

[[email protected] itcast]#chown -R mysql:mysql /var/lib/mysql //设置权限

[[email protected] itcast]#/etc/init.d/mysql restart //重新启动

ERROR! MySQL server PID file could not be found!

Starting MySQL...... SUCCESS! //启动成功

[[email protected] itcast]#mysql -u root -p //再次登录 成功

[[email protected] itcast]# /etc/init.d/mysql restart //启动服务 ERROR! MySQL server PID file could not be found! Starting MySQL................ ERROR! The server...

MySQL root密码重置报错:mysqladmin: connect to server at 'localhost' failed的解决方案

   我的是CentOS6.3+MySQL5.1.57。重启了一次服务器后,使用> mysql -u root -p登陆是出现下面的错误:

 

  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

1  登陆失败,mysqladmin修改密码失败

  于是,我检察mysql状态:

[[email protected] var]# mysqladmin -u root password '123456'

  > /etc/rc.d/init.d/mysqld status

mysqladmin: connect to server at 'localhost' failed

  显示stop,未运行。

error: 'Access denied for user 'root'@'localhost' (using password: NO)'

必赢手机登录网址 ,  >/etc/rc.d/init.d/mysqld restart

 

  Stopping mysqld: [ OK ]

2 停止mysql服务

  MySQL Daemon failed to start.

[[email protected] var]# /etc/init.d/mysqld stop

  Starting mysqld: [ FAILED]

Shutting down MySQL.... SUCCESS!

  >ps -ef | grep mysql

 

  root 28221 27474 0 14:18 pts/0 00:00:00 grep mysql 只有这一条

3 安全模式启动

  至此,我可以确定,mysql无法启动。

[[email protected] var]# mysqld_safe --skip-grant-tables &

  我开始排错,首先发现/tmp/mysql.sock不存在

/opt/mysql/product/5.5.25a/bin/mysqld_safe --skip-grant-tables &

  >vim /etc/my.cnf

[1] 10912

  socket=/var/lib/mysql/mysql .sock

[[email protected] var]# 110407 17:39:28 mysqld_safe Logging to '/usr/local/mysql/var//mysql.chinascopefinanical.com.err'.

  /var/lib/mysql/mysql .sock同样不存在

110407 17:39:29 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var/

  >find / -name mysql.sock

 

  显示为空,未查询到mysql.sock文件,mysql.sock文件丢失了。

4 无密码root帐号登陆

  我看网上有人说mysql.sock套接字文件可以简单地通过重启服务器重新创建得到它,

[[email protected] var]# /usr/bin/mysql -uroot -p 【注释,在下面的要求你输入密码的时候,你不用管,直接回车键一敲就过去了】

  >init 6 重启命令

Enter password:

  重启后发现错误还是那样,没有任何改变,mysql.sock重启服务器未自动生成。

Welcome to the MySQL monitor.  Commands end with ; or g.

  接下来了解到mysql.sock是一个临时文件,在mysql启动时会自动生成,我的服务器未启动,自然就没有mysql.sock文件。

Your MySQL connection id is 48

  我尝试安全启动模式,mysqld_safe试图通过工作目录找到服务器和数据库,但mysqld_safe还是失败。

Server version: 5.1.41-log Source distribution

  >mysqld_safe &

 

  Starting mysqld daemon with databases from ....../mysql/var

 

  STOPPING server from pid file .......pid

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

  130802 15:17:11 mysqld ended

 

  各种命令尝试无效的情况下,我开始了本次最大的收获----学会看错误日志。

 

必赢手机登录网址 1

mysql> use mysql;

  在错误日志中,启动失败的原因极为明显,file ‘./mysql-bin。000004’ not found,failed to open!

Database changed

  mysql开启了bin日志功能,到数据库根目录查看该文件是存在的,可能是文件权限的问题。

 

  >chown -R mysql:mysql /....../mysql/var

5 手动update修改密码

  >mysqld_safe &

mysql> update user set password=password("guxxxxxahyVh") where user='root' and host='localhost';

  >/etc/rc.d/init.d/mysqld restart

Query OK, 1 row affected (0.00 sec)

  Stopping mysqld: [ OK ]

Rows matched: 1  Changed: 1  Warnings: 0

  Starting mysqld: [ OK]

 

必赢手机登录网址 2

 

  成功启动了!~

mysql> flush privileges;

必赢手机登录网址 3

Query OK, 0 rows affected (0.00 sec)

  此时mysql.sock文件出现了,在/var/lib/mysql/mysql .sock。如下图所示,以”s”开头的文件都是socket文件。

 

必赢手机登录网址 4

 

  > mysql -u root -p

mysql> quit

  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Bye

  /tmp/mysql.sock

[[email protected] var]# mysql -uroot -pguNNhtqhjUnfky6ahyVh

  解决这个错误很简单,因为/tmp/mysql.sock不存在,用这样的方法:

Welcome to the MySQL monitor.  Commands end with ; or g.

  >ln -s /var/lib/mysql/mysql .sock /tmp/mysql .sock

Your MySQL connection id is 172

必赢手机登录网址 5

Server version: 5.1.41-log Source distribution

  以”l”开头的文件是软链接文件。或者可以通过修改/etc/my.cnf文件来修正它。

 

必赢手机登录网址 6

 

  成功解决了!~

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

  就是这样一个问题折腾了我这么久,错误日志让它无所遁形。查看错误日志可以明确问题所在,而不是像我之前那样盲目的找错。

 

  俗话说授人以鱼不如授人以渔,学会查看日志,你也可以方便快捷的解决问题了。

 

  错误使人进步,我与这个错误斗争了四个多小时,对linux的“一切皆文件”这句话有了更深的了解,对我学习文件系统管理(目录树)有很大的帮助,让我的思维真正的从windows操作系统转向成linux系统。并最终解决问题,很有成就感,我喜欢这种感觉。

mysql> quit

mysql -u root -p登陆是出现下面的错误: ERROR 2002 (HY000): Can't connect to local MySQL server thro...

Bye

 

 

6 正常重新启动

[[email protected] var]# service mysqld restart

Shutting down MySQL..110407 17:45:29 mysqld_safe mysqld from pid file /usr/local/mysql/var//mysql.chinascopefinanical.com.pid ended

SUCCESS!

Starting MySQL.. SUCCESS!

[1]+  Done                    mysqld_safe --skip-grant-tables

[[email protected] var]#

 

7 其他形式的错误情况分析

7.1 找不到sock 报错 :

[[email protected] mysqld]#  /usr/bin/mysql -uroot -p

Enter password: 

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

[[email protected] mysqld]# 

 

登陆的时候加上sock参数就OK了。

[[email protected] mysqld]#  /usr/bin/mysql -uroot -p --socket=/opt/mysqldata/mysql.sock

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or g.

Your MySQL connection id is 6

Server version: 5.1.69 Source distribution

 

 

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.

 

 

mysql> 

mysql> 

 

7.2 抱错 [ERROR] /usr/libexec/mysqld: Error writing file '/var/run/mysqld/mysqld.pid' (Errcode: 28)

130830 10:59:02  InnoDB: Initializing buffer pool, size = 1.0G

130830 10:59:02  InnoDB: Completed initialization of buffer pool

130830 10:59:02  InnoDB: Started; log sequence number 0 2727887496

130830 10:59:02 [ERROR] /usr/libexec/mysqld: Error writing file '/var/run/mysqld/mysqld.pid' (Errcode: 28)

130830 10:59:02 [ERROR] Can't start server: can't create PID file: No space left on device

130830 10:59:02 mysqld_safe Number of processes running now: 0

130830 10:59:02 mysqld_safe mysqld restarted

130830 10:59:02  InnoDB: Initializing buffer pool, size = 1.0G

130830 10:59:02  InnoDB: Completed initialization of buffer pool

130830 10:59:02  InnoDB: Started; log sequence number 0 2727887496

130830 10:59:02 [ERROR] /usr/libexec/mysqld: Error writing file '/var/run/mysqld/mysqld.pid' (Errcode: 28)

130830 10:59:02 [ERROR] Can't start server: can't create PID file: No space left on device

130830 10:59:03 mysqld_safe Number of processes running now: 0

130830 10:59:03 mysqld_safe mysqld restarted

130830 10:59:03  InnoDB: Initializing buffer pool, size = 1.0G

 

[分析]:不能写入默认的pid文件,就 修改 /etc/init.d/mysqld,把pid指向别的路经

 

[[email protected] mysqld]# vi /etc/init.d/mysqld

.....

get_mysql_option mysqld datadir "/var/lib/mysql"

datadir="$result"

get_mysql_option mysqld socket "$datadir/mysql.sock"

socketfile="$result"

get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"

errlogfile="$result"

首先发现/tmp/mysql.sock不存在,mysqladmin修改密码失败。get_mysql_option mysqld_safe pid-file "/opt/mysqldata/mysqld.pid"    # '/var/run/mysqld/mysqld.pid' 原始值,这里修改成别的路径/opt/mysqldata/mysqld.pid

mypidfile="$result"

.....

然后启动mysqld服务,OK,成功了。  

root密码重置报错:mysqladmin: connect to server at localhost failed的解决方案 1 登陆失败,mysqladmin修改密码失败 [[email protected] var]# mysqladmin -u root pas...