mysql启动报错-server PID file could not be found解决

  一般情况下,我们想要进入MySQL命令模式总是需要按如下交互输入密码确认,才能进入命令行模式:

mysql启动报错-server PID file could not be found解决

  [email protected]:~>
mysql -u sl -p

 

  Enter password:

[[email protected]
~]# service mysql stop

  其实我们完全可以使用expect编写脚本,来通来expect与shell交互通信来实现免密码登录:

MySQL server PID file could not be found!                  [失败]

  [email protected]:~>
cat mysql.sh

  www.2cto.com  

  #!/usr/local/bin/expect

解决方案如下:

  spawn /usr/local/services/mysql/bin/mysql -u sl -p

 

  expect {

首先查看下与mysql有关的进程

  ”assword” { send “slr” }

 

  }

[[email protected]
~]# ps aux |grep mysq*

  interact

root      2019  0.0  0.1   6228  1392 ?        S    09:22   0:00 /bin/sh
/usr/bin/mysqld_safe –datadir=/var/lib/mysql
–pid-file=/var/lib/mysql/yunhe.pid

  其实这段脚本的意思就是说“执行/usr/local/services/mysql/bin/mysql -u
sl
-p,等待响应,若匹配assword,则发送sl(即MySQL用户登录密码),回车,模拟用户手工操作”。

mysql     2115  0.0  2.9 353596 30808 ?        Sl   09:22   0:01
/usr/sbin/mysqld –basedir=/usr –datadir=/var/lib/mysql
–plugin-dir=/usr/lib/mysql/plugin –user=mysql
–log-error=/var/lib/mysql/yunhe.err –pid-file=/var/lib/mysql/yunhe.pid

  编写完mysql.sh脚本后,赋予执权限,然后就可以通过执行mysql.sh来免密码进入MySQL命令行模式。

500       4258  0.0  1.6  83432 17484 ?        S    09:35   0:01 gedit
/usr/share/mysql/my-medium.cnf

  [email protected]:~>
chmod +x mysql.sh

root      5555  0.0  0.0   5936   768 pts/0    S+   10:04   0:00 grep
mysq*

  [email protected]:~>
./mysql.sh

 

  spawn /usr/local/services/mysql/bin/mysql -u sl -p

如果看到上面的内容,那说明mysql相关的进程存在,不过资源调度出现了问题(好像卡死),这时用就要把这些卡死的进程都关闭。

  Enter password:

[[email protected]
~]# kill 2019

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

[[email protected]
~]# kill 20115

  Your MySQL connection id is 12912

-bash: kill: (20115) – 没有那个进程

  Server version: 5.5.14-log MySQL Community Server (GPL)

[[email protected]
~]# kill 2115

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

  www.2cto.com  

  Oracle is a registered trademark of Oracle Corporation and/or its

然后重新启动mysql

  affiliates. Other names may be trademarks of their respective

[[email protected]
~]# service mysql start

  owners.

Starting MySQL…                                          [确定]

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

[[email protected]
~]# mysql -u root -p

  mysql>

Enter password: 

  注:expect拥有众多的参数及丰富的应用场景,有兴趣的同学请自行查看man手册或其它资料。

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

http://www.bkjia.com/Mysql/434586.htmlwww.bkjia.comtruehttp://www.bkjia.com/Mysql/434586.htmlTechArticle一般情况下,我们想要进入MySQL命令模式总是需要按如下交互输入密码确认,才能进入命令行模式:
[email protected]:~
mysql -u sl -p Enter p…

Your MySQL connection id is 1

Server version: 5.6.4-m7 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2011, 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> 

 

http://www.bkjia.com/Mysql/488181.htmlwww.bkjia.comtruehttp://www.bkjia.com/Mysql/488181.htmlTechArticlemysql启动报错-server PID file could not be
found解决
[[email protected]
~]# service mysql stop MySQL server PID file could not be found!
[失败] www.2cto.com 解决方案如下: 首…