The mysql.server script using MySQL Tools

MySQL distributions on Unix and Unix-like system include a script named mysql.server, which starts the MySQL server using mysqld_safe. It can be used on systems such as Linux and Solaris that use System V-style run directories to start and stop system services. It is also used by the macOS Startup Item for MySQL.

mysql.server is for official Unixand the like Unixscripting system which contains the binary version of the installation package, which is a SHELLscript that is used to start, stop and see mysqldthe process of service. mysql.server In fact, the call is mysqld_safecommand.

More details on the mysql.server explanation can refer to the official document: https://dev.mysql.com/doc/refman/5.7/en/mysql-server.html

MySQL version is used herein 5.7.21.

# mysqld -V
mysqld  Ver 5.7.21 for linux-glibc2.12 on x86_64 (MySQL Community Server (GPL))
  • If RPMthe installation package to install the MySQL, the mysql.server script will be placed /etc/init.d/below, and was named mysqldor mysql;
  • If the installation is binary packages, the mysql.server on binary installation directory support-fileslist below.

The main usage

  • 1, start the mysqldservice
# mysql.server start      
  • 2, view the mysqldstatus of
# mysql.server status
  • 3. Stop mysqldService
# mysql.server stop
  • 4, restart the mysqldservice
# mysql.server restart
  • 5. Graceful Restart mysqldService
# mysql.server reload

customize

mysql.server is a SHELLscript, some of which are not specified in the options when there is a default value, such as basedirthe default path /usr/local/mysqland so on. Usually when a binary package is installed, and some need to customize the path, otherwise mysql.server can not find the path will not be able to complete the mysqldmanagement process services.

By VIMpeer editor mysql.server to edit and modify the script.

The main options to modify the path as follows:

1, add basedir, datadir and config configuration

Probably in the mysql.server script 43 rows at.

43 # If you change base dir, you must also change datadir. These may get                                                  
44 # overwritten by settings in the MySQL configuration files.                                                            
45                                                                                                                        
46 basedir=     #二进制包安装的目录                                                                                       
47 datadir=     #数据文件所在的目录
48 config=      #此处为新增选项,配置需要使用的参数文件路径 

Here may be amended as follows:

basedir=/usr/local/mysql5.7
datadir=/data/mysql/data
config=/data/mysql/3306/my.cnf

2, specify the PID files mysqld

 61 # The following variables are only set for letting mysql.server find things.
 62 
 63 # Set some defaults
 64 mysqld_pid_file_path=

Here may be amended as follows:

61 # The following variables are only set for letting mysql.server find things.
62 
63 # Set some defaults
64 mysqld_pid_file_path=/data/mysql/3306/mysql.pid

3, notes parse default parameter file method

mysqldWhen you start, find the default parameter file path as follows:

/etc/my.cnf ---> /etc/mysql/my.cnf ---> /usr/local/mysql/etc/my.cnf ---> ~/.my.cnf

The mysql.server script by default in this order to resolve (through the my_print_defaultsrealization of this command) these parameters file, in order to prevent mysql.server to resolve these parameter options parameter file them, then or by modifying mysql.server scripts options to achieve in order to use a custom parameter files.

Probably in the mysql.server script of 240 lines at.

229 #
230 # Read defaults file from 'basedir'.   If there is no defaults file there
231 # check if it's in the old (depricated) place (datadir) and read it from there
232 #
233 
234 extra_args=""
235 if test -r "$basedir/my.cnf"
236 then
237   extra_args="-e $basedir/my.cnf"
238 fi
239 
240 parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`

Notes can be 240 lines, as follows:

…………省略…………
237   extra_args="-e $basedir/my.cnf"
238 fi
239 
240 # 注释这行
240 # parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`

Such as by mysql.server start mysqldtime would not have to parse the parameter file in the default path

4, modify the parameter file at start mysqld_safe

By default, mysqld_safe startup option is not --defaults-filespecified parameters. This option can add parameters to specify the desired path.

Probably in the mysql.server script of 264 lines at.

264 # Give extra arguments to mysqld with the my.cnf file. This script
265 # may be overwritten at next upgrade.
266 $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
267 wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
268 

You can add confconfiguration:

# 此处配置的参数文件为前面新增选项的参数文件
266 $bindir/mysqld_safe --defaults-file="$config" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &

At this point, can now mysql.server to manage the mysqldprocess of state service, and can be placed /etc/init.d/under the management as a system service, of course, the premise is that the script must have executable permission.

reference

☆ 〖I is limited, the paper please leave a message if any errors also criticized the correction! ] ☆

Guess you like

Origin www.cnblogs.com/dbabd/p/11111757.html