代码: 全选
#!/bin/sh
#判断mysqld服务程序是否已经运行
res=$(ps aux | grep '/usr/sbin/mysqld' | wc -l)
#如果mysqld服务程序没有运行,则启动,否则不启动
if [ $res -gt 1 ]
then
bstop=1
sudo start mysql #这么写对吗?好像没有起作用
else
bstop=0
fi
echo $bstop
libmanager #我写的图书管理程序
#若程序启动了mysqld服务程序,则在结束时将其关闭
if [ $bstop eq 1 ]
sudo stop mysql
if
exit 0
代码: 全选
XXX 28625 0.0 0.0 3596 748 pts/1 S+ 19:16 0:00 grep --color=auto /usr/sbin/mysqld
代码: 全选
sudo /etc/init.d/mysql start
[sudo] password for XXX:
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql start
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mysql
mysql start/running, process 28698
XXX@XXX-freedom:~/bin$ ps aux | grep '/usr/sbin/mysqld'
mysql 28698 9.5 1.7 129168 17668 ? Ssl 19:17 0:00 /usr/sbin/mysqld
XXX 28781 0.0 0.0 3596 744 pts/1 S+ 19:17 0:00 grep --color=auto /usr/sbin/mysqld
代码: 全选
./libmanager.sh
0
请输入用户名:XXX
连接MySQL数据库失败,失败代码:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
初始化数据库失败,请启动mysql服务器,方法: sudo /etc/init.d/mysql start
或输入正确的用户名及密码
[: 22: 0: unexpected operator
因此我想请教各位:在Shell脚本里如何启动mysql服务程序?谢谢!