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. 001Java锁之synchronized

    01.synchronized & Lock synchronized锁同步 软件层面依赖JVM Lock锁同步 硬件层面依赖cpu指令 02.synchronized作用域 方法:锁住对象实 ...

  2. 03_Adaptive注解

    [Adaptive注解] package com.alibaba.dubbo.common.extension; import com.alibaba.dubbo.common.URL; import ...

  3. 139.00.006 Git学习-标签管理Tag

    @(139 - Environment Settings | 环境配置) 一.Why 发布一个版本时,我们通常先在版本库中打一个标签(tag),这样,就唯一确定了打标签时刻的版本.将来无论什么时候,取 ...

  4. 【Machine Learning】分类与回归 区别

    一.分类与回归的区别 两类监督学习 Classification Regression 分类和回归的区别在于输出变量的类型(而非输入变量). 定性输出称为分类,或者说是离散变量预测(discrete) ...

  5. java反射机制的简单介绍

    参考博客: https://blog.csdn.net/mlc1218559742/article/details/52754310 先给出反射机制中常用的几个方法: Class.forName (& ...

  6. WPF&Silverlight5 常用功能差异

    一晃从Wpf转到sl也有半年多了,总想总结一下wpf和sl的差异,今天终于下笔. 首先来个整体图: 通过上图可以发现其实sl只是使用了wpf的一小部分,只是sl依赖的freamwork有很大部分都一样 ...

  7. androidcookie

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { webSettings.setAllowFileAccessFrom ...

  8. react-native-mapbox-gl

    mapbox是基于谷歌地图集成的地图插件,可以在很多平台使用,具体可以看mapbox官网.这里具体讲解“react-native-mapbox-gl”插件,是mapbox结合react native封 ...

  9. Atlas+Keepalived实现MySQL读写分离、读负载均衡

    一.基础介绍 ========================================================================================== 1. ...

  10. Redis缓存方案

    1 Redis简介 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis的开发 ...