ITPub博客

首页 > 数据库 > MySQL > mysqld与mysqld_safe

mysqld与mysqld_safe

原创 MySQL 作者:神谕丶 时间:2015-08-25 14:59:48 0 删除 编辑
在一些场景下,通常使用 mysqld_safe &来启动mysql,mysqld是什么进程呢?

启动实例之后,可以通过ps来查看一下mysql的进程,发现其中不仅仅有mysqld_safe,还有一个mysqld进程。

op        4546     1  0 13:13 ?        00:00:00 /bin/sh ../bin/mysqld_safe
op       10168  4546  0 13:42 ?        00:00:00 /home/op/software/mysql/bin/mysqld --basedir=/home/op/software/mysql --datadir=/home/op/software/mysql/data --plugin-dir=/home/op/software/mysql/lib/plugin --log-error=/home/op/software/mysql/data/localhost.localdomain.err --pid-file=/home/op/software/mysql/data/localhost.localdomain.pid
op       13814  8439  0 14:01 pts/1    00:00:00 grep mysql

mysqld进程就是最基本的mysql的服务器了
man mysqld的描述如下:

       mysqld, also known as MySQL Server, is the main program that does most

       of the work in a MySQL installation. MySQL Server manages access to the

       MySQL data directory that contains databases and tables. The data

       directory is also the default location for other information such as

       log files and status files.

实质上,用rpm或者yum这类包管理的工具,在linux下安装时,所执行的 service mysqld start也就是启动的这个进程。

而mysqld_safe呢?我man mysqld_safe了一下:


       mysqld_safe is the recommended way to start a mysqld server on Unix.

       mysqld_safe adds some safety features such as restarting the server

       when an error occurs and logging runtime information to an error log

       file. A description of error logging is given later in this section.

       mysqld_safe tries to start an executable named mysqld. To override the

       default behavior and specify explicitly the name of the server you want

       to run, specify a --mysqld or --mysqld-version option to mysqld_safe.

       You can also use --ledir to indicate the directory where mysqld_safe

       should look for the server.


按mysqld_safe的manual信息来说,它是一个当mysqld崩掉以后,能够再次将mysqld启动起来的进程。

测试:


[op@localhost ~]$ ps -ef | grep mysql
op        4546     1  0 13:13 ?        00:00:00 /bin/sh ../bin/mysqld_safe
op       10168  4546  0 13:42 ?        00:00:00 /home/op/software/mysql/bin/mysqld --basedir=/home/op/software/mysql --datadir=/home/op/software/mysql/data --plugin-dir=/home/op/software/mysql/lib/plugin --log-error=/home/op/software/mysql/data/localhost.localdomain.err --pid-file=/home/op/software/mysql/data/localhost.localdomain.pid
op       19643  8439  0 14:31 pts/1    00:00:00 grep mysql
[op@localhost ~]$ kill -9 10168
[op@localhost ~]$ ps -ef | grep mysql
op        4546     1  0 13:13 ?        00:00:00 /bin/sh ../bin/mysqld_safe
op       19702  4546  4 14:31 ?        00:00:00 /home/op/software/mysql/bin/mysqld --basedir=/home/op/software/mysql --datadir=/home/op/software/mysql/data --plugin-dir=/home/op/software/mysql/lib/plugin --log-error=/home/op/software/mysql/data/localhost.localdomain.err --pid-file=/home/op/software/mysql/data/localhost.localdomain.pid
op       19736  8439  0 14:31 pts/1    00:00:00 grep mysql

此时,mysqld的进程号被修改为19702(之前是10168)
其父进程仍然为4546。

mysqld在mysqld_safe的“守卫”下,再一次的被启动起来。

正常关闭mysql:
[op@localhost bin]$ ./mysqladmin shutdown -uroot -p
Enter password: 
[op@localhost bin]$ ps -ef | grep mysql
op       21877 21454  0 14:42 pts/0    00:00:00 grep mysql

重新启动之后:
[op@localhost bin]$ ps -ef |grep -v  ‘grep’ | grep mysql
op       22482    1  0 14:45 pts/0    00:00:00 /bin/sh ./mysqld_safe
op       22568 22482  1 14:45 pts/0    00:00:00 /home/op/software/mysql/bin/mysqld --basedir=/home/op/software/mysql --datadir=/home/op/software/mysql/data --plugin-dir=/home/op/software/mysql/lib/plugin --log-error=/home/op/software/mysql/data/localhost.localdomain.err --pid-file=/home/op/software/mysql/data/localhost.localdomain.pid
[op@localhost bin]$ kill -9 22482
[op@localhost bin]$ ps -ef |grep -v 'grep'| grep mysql
op       22568     1  0 14:45 pts/0    00:00:00 /home/op/software/mysql/bin/mysqld --basedir=/home/op/software/mysql --datadir=/home/op/software/mysql/data --plugin-dir=/home/op/software/mysql/lib/plugin --log-error=/home/op/software/mysql/data/localhost.localdomain.err --pid-file=/home/op/software/mysql/data/localhost.localdomain.pid

杀掉父进程也就是mysqld_safe之后,检查一下,确实杀掉了。

再次杀掉mysqld进程:
[op@localhost bin]$ kill -9 22568
[op@localhost bin]$ ps -ef |grep -v 'grep'| grep mysql
[op@localhost bin]$

发现已经没有mysql相关进程了。

说明在mysqld_safe的情况下,mysqld如果“意外”退出,mysqld_safe会守卫mysqld,并保证其一直启动。


作者公众号(持续更新)


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29773961/viewspace-1782187/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
微信公众号:fantasy-life-

注册时间:2014-07-28

  • 博文量
    159
  • 访问量
    975914