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. 《Visual C++ 2010入门教程》系列一:关于Visual Studio、VC和C++的那些事

    原文:http://www.cnblogs.com/Mrt-02/archive/2011/07/24/2115606.html 作者:董波 日期:2010.6.15 写在前面 在我还在上学的时候,我 ...

  2. WCF传输协议

    典型传输协议下的(1)HTTP和HTTPSHTTPS(安全超文本传输协议).它是为了在WWW上解决安全的数据传输而设计的.HTTS是采用了SSL的HTTP,SSL是一种加密协议.它们默认的端口号分别是 ...

  3. python 测试:生成exe文件

    任务: test.py print(input('请输入:')) 将test.py生成test.exe 解答: 安装: pip install pyinstaller 命令使用: (绝对地址)pyin ...

  4. Windows下Redis集群配置

    Redis集群学习地址:http://blog.csdn.net/dc_726/article/details/11694437 Windows-32系统下搭建Redis集群 一.Redis主从同步原 ...

  5. spring core

    https://docs.spring.io/spring/docs/5.1.3.RELEASE/spring-framework-reference/core.html#beans

  6. HashMap 和 ConcurrentHashMap,Java1.8版本

    1. HashMap Entry,一对kv就是一个Entry,还包括一些next指针,用来解决散列冲突. table,内部用来存储Entry的数组,resize时候table会成倍扩容. 容量,tab ...

  7. background-color和background-image相关细节

    1.background-color 是以border-box作为他的左上角来定位的 2.background-image 默认是以padding-box作为他的左上角来定位的 3.backgroun ...

  8. HTTP 中状态码 302的使用场景

    一直都知道302是临时重定向,可是不懂为什么要用这个,直到看到了这个 这样就可以用一个URL,来访问其他的URL上的资源了,非常的nice

  9. Eclipse Ctrl + Shift + O in IntelliJ IDEA

    In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For Inte ...

  10. Linux 统计文件夹,文件数量的命令

    用的最多的就是: ls -l | grep "^-" | wc -l ls -l 普通文件就是以 - 开头,文件夹以 d 开头 grep 后面接正则表达式:^- 以 - 开头的匹配 ...