(3.5)mysql基础深入——mysqld_safe脚本功能及流程

时间:2023-12-21 22:50:32

(3.5)mysql基础深入——mysqld_safe脚本功能及流程

目录

1、mysqld_safe过程总结

2、mysql_safe启动的好处

3、mysqld_safe 参数

4、mysqld_safe流程

详情:

1、mysqld_safe过程总结

  【1.1】检查环境变量  【1.2】检查配置文件中的选项  【1.3】启动mysqld及启动后的一些处理

2、mysql_safe启动的好处

  【2.1】安全性好(出现问题重启的时候,会向错误日志里面写入相关运行时间)

  【2.2】启动时指定一些关于mysqld_safe的参数,也可以放在my.cnf里的 [mysqld_safe]

  【2.3】ulimit -c $core_file_size(文件大小)

  【2.4】unlimit -n $size(最多支持的打开文件数量)

  【2.5】检查环境变量,检查配置文件,检查指定的选项

3、mysqld_safe 参数

  

 --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)

4、mysqld_safe流程

【4.1】查看basedir和ledir

【4.2】查看datadir和my.cnf

【4.3】对my.cnf做一些检查

【4.4】解析My.cnf中的组 [mysqld] 和 [mysqld_safe] 并和中毒案例输入的命令合并。

【4.5】调用parse_arguments函数解析用户传递(就是【4】中的)的所有参数($@)

【4.6】对系统日志和错误日志的判断和做出相应的处理,及选项--err-log参数的复制。

【4.7】对选项--user , --pid-file , --socket 及 --port 进行处理及复制,保证启动时如果不给出这些参数也会有值。

【4.8】启动mysqld

  (1)启动时会判断一个进程号是否存在,如果存在那么久在错误日志中记录 "A mysqld process already exists" 并且退出

  (2)如果不存在就删除进程文件,如果删除不了,那么久在错误日志中记录 "Fatal error : Can't remove the pid file" 并退出。

【4.9】启动时对表进行检查。如果启动的时候检查表的话设置key_buffer and sort_buffer 会提高速度并且减少磁盘空间的使用。

【4.10】如果启动时什么参数都没有显示指定,那么它会选用一些特定的参数,具体参数看【3】

【4.11】如果服务器异常关闭,那么会restart。