today,one buddy in IMG wechat group 2 asked "why i've installed the MySQL 5.7 on linux server,but there's no mysqld_safe command at all?"so,here i'd like to post this article to say something about it.first of all,let's see the command parameter and usage:

 #mysqld_safe --help
Usage: /usr/local/mysql/bin/mysqld_safe [OPTIONS]
The following options may be given as the first argument:
--no-defaults Don't read the system defaults file
--defaults-file=FILE Use the specified defaults file
--defaults-extra-file=FILE Also use defaults from the specified file Other options:
--ledir=DIRECTORY Look for mysqld in the specified directory
--open-files-limit=LIMIT Limit the number of open files
--core-file-size=LIMIT Limit core files to the specified size
--timezone=TZ Set the system timezone
--malloc-lib=LIB Preload shared library LIB if available
--mysqld=FILE Use the specified file as mysqld
--mysqld-version=VERSION Use "mysqld-VERSION" as mysqld
--nice=NICE Set the scheduling priority of mysqld
--plugin-dir=DIR Plugins are under DIR or DIR/VERSION, if
VERSION is given
--skip-kill-mysqld Don't try to kill stray mysqld processes
--syslog Log messages to syslog with 'logger'
--skip-syslog Log messages to error log (default)
--syslog-tag=TAG Pass -t "mysqld-TAG" to 'logger'
--mysqld-safe-log- TYPE must be one of UTC (ISO UTC),
timestamps=TYPE system (ISO local time), hyphen
(hyphenated date a la mysqld 5.6), legacy
(legacy non-ISO mysqld_safe timestamps) All other options are passed to the mysqld program. [root@zlm3 :: /data/mysql/mysql3306]
#

    the most simplest usage of mysqld_safe way is to just use '--defaults-file' to specify which "my.cnf" you want to use,just like:

 [root@zlm3 :: /usr/local/mysql/bin]
#pkill mysqld [root@zlm3 :: /usr/local/mysql/bin]
#ps aux|grep mysqld
root 0.0 0.0 pts/ R+ : : grep --color=auto mysqld [root@zlm3 :: /usr/local/mysql/bin]
#mysqld_safe --defaults-file=/data/mysql/mysql3306/my.cnf &
[] [root@zlm3 :: /usr/local/mysql/bin]
#--04T05::.758814Z mysqld_safe Logging to '/data/mysql/mysql3306/data/error.log'.
--04T05::.786306Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql3306/data
^C [root@zlm3 :: /usr/local/mysql/bin]
#ps aux|grep mysqld
root 0.1 0.1 pts/ S : : /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql3306/my.cnf
mysql 1.0 17.4 pts/ Sl : : /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=error.log --open-files-limit= --pid-file=mysql.pid --socket=/tmp/mysql3306.sock --port=
root 0.0 0.0 pts/ R+ : : grep --color=auto mysqld [root@zlm3 :: /usr/local/mysql/bin]
#

    here we can see,there're two processes running,one is mysqld_safe,another one is the mysqld.even if you use "kill -9 7328" to stop the mysqld process,but subsequently you'll find that the mysqld will startup again soon,unless you kill mysqld process by using "pkill mysqld" as below:

 [root@zlm3 :: /usr/local/mysql/bin]
#kill - [root@zlm3 :: /usr/local/mysql/bin]
#/usr/local/mysql/bin/mysqld_safe: line : Killed nohup /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=error.log --open-files-limit= --pid-file=mysql.pid --socket=/tmp/mysql3306.sock --port= < /dev/null > /dev/null >&
--04T05::.076914Z mysqld_safe Number of processes running now:
--04T05::.083092Z mysqld_safe mysqld restarted
^C [root@zlm3 :: /usr/local/mysql/bin]
#ps aux|grep mysqld
root 0.0 0.1 pts/ S : : /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql3306/my.cnf
mysql 2.4 17.7 pts/ Sl : : /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=error.log --open-files-limit= --pid-file=mysql.pid --socket=/tmp/mysql3306.sock --port=
root 0.0 0.0 pts/ R+ : : grep --color=auto mysqld [root@zlm3 :: /usr/local/mysql/bin]
#pkill mysqld [root@zlm3 :: /usr/local/mysql/bin]
#--04T05::.957789Z mysqld_safe mysqld from pid file /data/mysql/mysql3306/data/mysql.pid ended
^C
[]+ Done mysqld_safe --defaults-file=/data/mysql/mysql3306/my.cnf [root@zlm3 :: /usr/local/mysql/bin]
#ps aux|grep mysqld
root 0.0 0.0 pts/ R+ : : grep --color=auto mysqld [root@zlm3 :: /usr/local/mysql/bin]
#
    why will that happen?the consequence is trigged by mysqld_safe which can protect mysqld from killing by some command like "kill -9" accidentally.or in the other case,the mysqld process shuted down by the OS because of some unknowing issue or bug.that will help you to prevent the application from disconnecting the MySQL server when mysqld process down.but why the buddy's MySQL server hasnot the mysqld_safe command?here's the explaination:
 

Note

For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. On these platforms, mysqld_safe is not installed because it is unnecessary. For more information, see Section 2.5.9, “Managing MySQL Server with systemd”.


    therefore,if you want the mysqld_safe feature,i rather recommend you to install MySQL server with binary distribution instead of rpm distribution.

someone said that mysqld_safe will not be supported in the future release,but what i've seen is the version 8.0 official document is that it still be recommended:
 

 MySQL 8.0 Reference Manual  /  ...  /  mysqld_safe — MySQL Server Startup Script

4.3.2 mysqld_safe — MySQL Server Startup Script

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. A description of error logging is given later in this section.

来源: https://dev.mysql.com/doc/refman/8.0/en/mysqld-safe.html


summary:

    another buddy in zst techique wechat group said that it will be messy in troubleshooting while using mysqld_safe to startup mysqld,'cause in some case,the mysqld_safe may lead to the ceaseless restarting of mysqld.furthermore,it may destroy the evidences and logs which can be diagnosted by DBAs.anyhow,in my opinion it depends:

  • if the bussines continuity is the first thing you need to consider,i recommend to use mysqld_safe method.
  • if your monitor system is strong enough or the application on the MySQL server is not so important such as enterprise management system,BBS system,i recommend to use mysqld method.

mysqld_safe之三言两语的更多相关文章

  1. 执行mysqld_safe报错:mysqld does not exist or is not executable

    执行mysqld_safe报错: [root@edu data]# /usr/local/mysql5.7/bin/mysqld_safe --user=mysql160427 12:41:28 my ...

  2. 三言两语之微信小程序开发初体验(1)

    一.前情   直接切入主题,微信发布了小程序,前端开发者表示,如果不会微信小程序的开发感觉就跟不上时代了,先解答几个容易出现歧义的问题 小程序就叫小程序,不叫应用号,因为apple不准,哈哈 小程序是 ...

  3. 关于Mysql错误:./bin/mysqld_safe --user=mysql& [1] 32710 121003 16:40:22 mysqld_safe Logging to '/var/log/mysqld.log'. 121003 16:40:22 mysqld_s

    [root@www]# ./bin/mysqld_safe --user=mysql&[1] 32710[root@www]# 121003 16:40:22 mysqld_safe Logg ...

  4. mysqld_safe启动报错 mysqld_safe The file /usr/local/mysql/bin/mysqld does not exist or is not executable

    报错(如下),但是使用mysqld直接启动没有问题. 150718 00:03:38 mysqld_safe Logging to '/var/log/mysqld.log'. 150718 00:0 ...

  5. Error with mysqld_safe

    出处:http://bugs.mysql.com/bug.php?id=18403 Description: - I downloaded the binary file “Standard 5.0. ...

  6. 启动mysql错误解决方案,学会查看错误日志:mysql.sock丢失,mysqld_safe启动报错

    本人还是个菜鸟,下面是我的经验之谈,能解决一些问题,有不对的地方,敬请斧正. 我的是CentOS6.3+MySQL5.1.57. 重启了一次服务器后,使用> mysql -u root -p登陆 ...

  7. [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist 160913 02:11:21 mysqld_safe mysqld from pid file /tmp/mysql.pid ended

    -- :: [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 -- :: [Warning] InnoDB: New ...

  8. 【国庆】记一次mysqld_safe引发mysql进程故障

    今天是举国欢庆的日子,但是Mariadb密码忘记了,于是巴拉巴拉的执行"mysqld_safe --skip-grant-tables &"这个神技能,打算跳过密码验证,直 ...

  9. Linux下忘记MySQL密码的解决方法和输入mysqld_safe --skip-grant-tables &后无法进入MySQL的解决方法

    在Linux下忘记MySQL密码后我们可以通过一个mysql的参数--skip-grant-tables &轻松解决这个问题 亲测在CentOS有效 其中 --skip-grant-table ...

随机推荐

  1. vue-router 的使用

    vue-router 是 vue  的  一个特色. 下面介绍vue-router 的使用: 一.先将vue-router作为vue 的一个插件使用 import Vue from 'vue' imp ...

  2. HTTP状态码302、303、307区别

    HTTP状态码3XX表示重定向,表明浏览器需要执行某些特殊的处理以正确处理请求. 301 Moved Permanently 永久性定向.该状态码表示请求的资源已被分配了新的URI,以后应使用资源现在 ...

  3. C++ VS编译问题--VS下生成DLL,但没有生成Lib的解决办法

    如果项目生成了.dll文件,但是没有生成.lib文件,这是由于项目的设置错误,应作如下修改: 项目->属性->链接器->输入->模块定义文件,设置你的模块定义文件,默认为lib ...

  4. 【Machine Learning】监督学习、非监督学习及强化学习对比

    Supervised Learning Unsupervised Learning Reinforced Learning Goal: How to apply these methods How t ...

  5. springmvc/springboot处理前台字符串日期自动转换成后台date类型的三种办法

    参考https://blog.csdn.net/eumenides_/article/details/79033505 补充一个:Formatter也可以实现.

  6. 第四次工业革命:人工智能(AI)入门

    转载自 http://www.infoq.com/cn/articles/the-fourth-industrial-revolution-an-introduction-to-ai "过去 ...

  7. 高精度定时器实现 z

    1背景Permalink .NET Framework 提供了四种定时器,然而其精度都不高(一般情况下 15ms 左右),难以满足一些场景下的需求. 在进行媒体播放.绘制动画.性能分析以及和硬件交互时 ...

  8. 监控DAG状态

    Add-PSSnapin microsoft.exchange* Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 $server ...

  9. Hadoop学习---Eclipse中hadoop环境的搭建

    在eclipse中建立hadoop环境的支持 1.需要下载安装eclipse 2.需要hadoop-eclipse-plugin-2.6.0.jar插件,插件的终极解决方案是https://githu ...

  10. 修改virtual box中ubuntu lubuntu 的分辨率

    Step1 先用xrandr命令查看能够支持的分辨率 Step2 xrandr --output VGA-1 --size 1280x800 Step3 重启电脑