mysqld_safe之三言兩語

来源:https://www.cnblogs.com/aaron8219/archive/2018/06/03/9129981.html
-Advertisement-
Play Games

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 l ...


 

    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:

 

 1 #mysqld_safe --help
 2 Usage: /usr/local/mysql/bin/mysqld_safe [OPTIONS]
 3  The following options may be given as the first argument:
 4   --no-defaults              Don't read the system defaults file
 5   --defaults-file=FILE       Use the specified defaults file
 6   --defaults-extra-file=FILE Also use defaults from the specified file
 7 
 8  Other options:
 9   --ledir=DIRECTORY          Look for mysqld in the specified directory
10   --open-files-limit=LIMIT   Limit the number of open files
11   --core-file-size=LIMIT     Limit core files to the specified size
12   --timezone=TZ              Set the system timezone
13   --malloc-lib=LIB           Preload shared library LIB if available
14   --mysqld=FILE              Use the specified file as mysqld
15   --mysqld-version=VERSION   Use "mysqld-VERSION" as mysqld
16   --nice=NICE                Set the scheduling priority of mysqld
17   --plugin-dir=DIR           Plugins are under DIR or DIR/VERSION, if
18                              VERSION is given
19   --skip-kill-mysqld         Don't try to kill stray mysqld processes
20   --syslog                   Log messages to syslog with 'logger'
21   --skip-syslog              Log messages to error log (default)
22   --syslog-tag=TAG           Pass -t "mysqld-TAG" to 'logger'
23   --mysqld-safe-log-         TYPE must be one of UTC (ISO 8601 UTC),
24     timestamps=TYPE          system (ISO 8601 local time), hyphen
25                              (hyphenated date a la mysqld 5.6), legacy
26                              (legacy non-ISO 8601 mysqld_safe timestamps)
27 
28 All other options are passed to the mysqld program.
29 
30 [root@zlm3 07:43:01 /data/mysql/mysql3306]
31 #

 

    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:

 

 1 [root@zlm3 07:54:10 /usr/local/mysql/bin]
 2 #pkill mysqld
 3 
 4 [root@zlm3 07:54:40 /usr/local/mysql/bin]
 5 #ps aux|grep mysqld
 6 root      6302  0.0  0.0 112640   960 pts/0    R+   07:54   0:00 grep --color=auto mysqld
 7 
 8 [root@zlm3 07:54:51 /usr/local/mysql/bin]
 9 #mysqld_safe --defaults-file=/data/mysql/mysql3306/my.cnf &
10 [1] 6307
11 
12 [root@zlm3 07:55:21 /usr/local/mysql/bin]
13 #2018-06-04T05:55:21.758814Z mysqld_safe Logging to '/data/mysql/mysql3306/data/error.log'.
14 2018-06-04T05:55:21.786306Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql3306/data
15 ^C
16 
17 [root@zlm3 07:55:35 /usr/local/mysql/bin]
18 #ps aux|grep mysqld
19 root      6307  0.1  0.1 113252  1628 pts/0    S    07:55   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql3306/my.cnf
20 mysql     7328  1.0 17.4 1069424 177592 pts/0  Sl   07:55   0:00 /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=65535 --pid-file=mysql.pid --socket=/tmp/mysql3306.sock --port=3306
21 root      7361  0.0  0.0 112640   960 pts/0    R+   07:55   0:00 grep --color=auto mysqld
22 
23 [root@zlm3 07:55:44 /usr/local/mysql/bin]
24 #

 

    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:

 

 1 [root@zlm3 07:55:44 /usr/local/mysql/bin]
 2 #kill -9 7328
 3 
 4 [root@zlm3 07:57:15 /usr/local/mysql/bin]
 5 #/usr/local/mysql/bin/mysqld_safe: line 198:  7328 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=65535 --pid-file=mysql.pid --socket=/tmp/mysql3306.sock --port=3306 < /dev/null > /dev/null 2>&1
 6 2018-06-04T05:57:15.076914Z mysqld_safe Number of processes running now: 0
 7 2018-06-04T05:57:15.083092Z mysqld_safe mysqld restarted
 8 ^C
 9 
10 [root@zlm3 07:57:20 /usr/local/mysql/bin]
11 #ps aux|grep mysqld
12 root      6307  0.0  0.1 113256  1676 pts/0    S    07:55   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql3306/my.cnf
13 mysql     7385  2.4 17.7 1081288 180624 pts/0  Sl   07:57   0:00 /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=65535 --pid-file=mysql.pid --socket=/tmp/mysql3306.sock --port=3306
14 root      7419  0.0  0.0 112640   960 pts/0    R+   07:57   0:00 grep --color=auto mysqld
15 
16 [root@zlm3 07:57:24 /usr/local/mysql/bin]
17 #pkill mysqld
18 
19 [root@zlm3 07:57:37 /usr/local/mysql/bin]
20 #2018-06-04T05:57:38.957789Z mysqld_safe mysqld from pid file /data/mysql/mysql3306/data/mysql.pid ended
21 ^C
22 [1]+  Done                    mysqld_safe --defaults-file=/data/mysql/mysql3306/my.cnf
23 
24 [root@zlm3 07:57:48 /usr/local/mysql/bin]
25 #ps aux|grep mysqld
26 root      7439  0.0  0.0 112640   956 pts/0    R+   07:57   0:00 grep --color=auto mysqld
27 
28 [root@zlm3 07:57:55 /usr/local/mysql/bin]
29 #

 

    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”.

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

 

    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 


 

    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.

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 在又是就業的高峰期了,我公司天天都有過來面試的,這不大學生們也都畢業了,今天這位小伙子就是個奇葩,面試不好好做酷炫特效或者能夠讓面試官眼前一輛的代碼,卻畫起了畫,面試官表示: 相信有很多學習大數據的道友,在這裡我給大家說說我滴群哦,大數據海量知識分享,784789432.在此我保證,絕對大數據的乾貨 ...
  • hive在查詢表信息時,中文顯示亂碼,數字或者url顯現null問題解決思路。 1、確定create hive表時指定的row format delimited fields terminated by ‘xxx’中“xxx”格式是否和原始導入表的data的行列分隔格式一致,如不一致,則會出現sel ...
  • oracle 11.2.0 expdp/impdp 數據泵參數 expdp參數 ATTACH 附加目前已有Job中。例如ATTACH=Job_name. CLUSTER 利用cluster或RAC分散式資源。設定值CLUSTER=[Y]/N 預設值為Y COMPRESSION 導出檔案的壓縮。設定值 ...
  • 目前,市場上的大數據產品太多,但遠遠低於IAAS的標準化水平,各產品之間的差異還不十分清楚。當許多公司正在製造大數據平臺或大數據解決方案時,他們往往不知道選擇哪些產品來滿足他們的需求。一般的做法是做研究、學習、建造環境、測試和整合各種產品,但通常這個過程很長,而且成本很高。如果你想瞭解大數據的學習路 ...
  • 原文:https://blog.csdn.net/andrewniu/article/details/78485312 原文:https://jingyan.baidu.com/article/76a7e40909b961fc3b6e1519.html ...
  • 一.概述 講到sql server鎖管理時,感覺它是一個大話題,因為它不但重要而且涉及的知識點很多,重點在於要掌握高併發要先要掌握鎖與事務,涉及的知識點多它包括各式各樣的鎖,鎖的組合,鎖的排斥,鎖延伸出來的事務隔離級別, 鎖住資源帶來的阻塞,鎖之間的爭用造成的死鎖,索引數據與鎖等。這次介紹鎖和事務, ...
  • 實驗一:實驗案例一(附加“練慣用的可以附加的資料庫--class”) 1、在products表中查詢出廠日期晚於2014年4月的水果信息。 select * from products where 出廠日期>'2014-04-30 ' 2、在products表中分組查詢所有水果,蔬菜,堅果的總成本。 ...
  • 本文重點談交易型分散式資料庫的關鍵設計點,這裡並不針對具體的產品而是以普適性的結構,結合NoSQL與NewSQL的差異,從縱向來談談OLTP場景“分散式資料庫”實現方案的關鍵技術要點。算是分散式資料庫專題文章的一個總綱,其中的要點Ivan之後也會單獨撰文闡述。 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...