Mysql secure STARTUP script mysqld_safe for details, mysqlmysqld_safe
Mysqld_safe is recommended in Unix and NetWare to start the mysqld server. Mysqld_safe adds some security features, such as restarting the server when an error occurs and writing runtime information to the error log file. This section describes the specific actions of NetWare.
Note: To maintain backward compatibility with the old version of MySQL, the binary distribution of MySQL still includes safe_mysqld as the symbolic link of mysqld_safe. However, you should not rely on it any more, because it will be deleted in the future.
By default, mysqld_safe tries to start and execute mysqld-max (if any). Otherwise, mysqld is started. The meaning of this behavior is:
· In Linux, MySQL-Max RPM depends on the behavior of mysqld_safe. You can run mysqld-max during RPM installation to enable mysqld_safe to automatically use executable commands from this point.
· If you install the MySQL-max distribution version that includes the mysqld-Max server and upgrade it to a non-Max MySQL version later, mysqld_safe still tries to run the old mysqld-max server. During the upgrade, You Should manually delete the old mysqld-max server to ensure that mysqld_safe runs the new mysqld server.
To bypass the default behavior and explicitly specify the server you want to run, specify -- mysqld or -- mysqld-version for mysqld_safe.
Mysqld_safe reads all options from the [mysqld], [server], and [mysqld_safe] sections of the Option file. To ensure backward compatibility, it also reads the [safe_mysqld] section, although you should rename this Part as [mysqld_safe] During MySQL 5.1 installation.
Mysqld_safe supports the following options:
·-- Help
Displays the help message and exits.
·-- Autoclose
(Only in NetWare) in NetWare, mysqld_safe can keep the window. When you disable mysqld_safe NLM, the window does not disappear according to the default settings. Instead, it prompts the user to enter:
* <NLM has terminated; Press any key to close the screen> * If you want NetWare to automatically close the window, use the -- autoclose option in mysqld_safe.
·--Basedir = path
Path of the MySQL installation directory.
·--Core-file-size = size
The size of the kernel file that mysqld can create. The option value is passed to ulimit-c.
· -- Datadir = path
The path of the data directory.
·-- Defaults-extra-file = path
Except the option file name read by the common option file. This option must be preferred if given.
·-- Defaults-file = path
The option file name that is read to replace the common option file. This option must be preferred if given.
·-- Ledir = path
Directory that contains the mysqld program. This option is used to explicitly represent the server location.
·-- Log-error = path
Write the error log to the specified file. See section 5.11.1 "error log ".
·-- Mysqld = prog_name
Name of the server program to be started (in the ledir directory ). This option is required if you use the MySQL binary distribution version but have Data Directories other than the binary distribution version.
·-- Mysqld-version = suffix
This option is similar to the -- mysqld option, but you only specify the suffix of the server program name. The basic name is mysqld. For example, if you use -- mysqld-version = max, mysqld_safe to start the mysqld-max program in the ledir directory. If the -- mysqld-version parameter is null, mysqld_safe uses mysqld in the directory.
·-- Nice = priority
Use the nice program to set the scheduling priority of the server based on the given value.
·-- No-defaults
Do not read any option files. This option must be preferred if given.
·-- Open-files-limit = count
The number of files that mysqld can open. The option value is passed to ulimit-n. Please note that you need to use root to start mysqld_safe to ensure proper work!
·-- Pid-file = path
Path of the process ID file.
·-- Port = port_num
The port number used for frame listening TCP/IP connection. The port number must be 1024 or greater, unless MySQL runs as a root user.
·-- Skip-character-set-client-handshake
Ignore the character set information sent by the client and use the default Character Set of the server. (Select this option. The action of MySQL is the same as that of MySQL 4.0 ).
·-- Socket = path
The Unix socket file used for local connection.
·-- Timezone = zone
Set the TZ time zone environment variable for the given option value. View the valid time zone format in the operating system documentation.
·-- User = {user_name | user_id}
Run the mysqld server with user_name or digital user ID user_id. ("User" in this article refers to the Logon account of the system, rather than the MySQL user in the authorization table ).
When executing mysqld_safe, you must first provide -- defaults-file or -- defaults-extra-option, or do not use the option file. For example, this command does not use the option file:
In contrast to mysqld_safe -- port = port_num -- defaults-file = file_name, run the following command:
Mysqld_safe -- defaults-file = file_name -- port = port_num generally, the mysqld_safe script can start the server installed from the source code or binary MySQL distribution edition, even if these distributions install servers in a slightly different location. (See section 2.1.5 "installation layout "). Mysqld_safe expects one of the following conditions to be true:
· You can find the server and database based on the directory that calls mysqld_safe. In the binary distribution version, mysqld_safe looks to be in the working directory of the bin and data Directories. For the source code distribution version, it is the libexec and var directories. If you execute mysqld_safe from the MySQL installation directory, this condition should be met (for example, the binary distribution version is/usr/local/mysql ).
· If the server and database cannot be found based on the working directory, mysqld_safe tries to locate them through the absolute path. The typical locations are/usr/local/libexec and/usr/local/var. The actual location is determined by the value configured during the build of the distribution edition. If MySQL is installed to the location specified during the configuration, they should be correct.
Because mysqld_safe tries to find the server and database through the working directory, as long as you run mysqld_safe from the MySQL installation directory, you can install the MySQL binary distribution to another location:
Shell> cd mysql_installation_directoryshell> bin/mysqld_safe & if mysqld_safe fails, even if the call from the MySQL installation directory still fails, you can specify the -- ledir and -- datadir options to indicate the installation directory of the server and the data library in your system.
In general, you should not edit the mysqld_safe script. Instead, configure mysqld_safe using the options in the command line option or the [mysqld_safe] section of the my. cnf option file. In general, you do not need to edit mysqld_safe to correctly start the server. However, if you edit it, MySQL will overwrite the modified mysqld_safe version after you upgrade it. Therefore, you should back up the modified version for future reinstallation.
In NetWare, mysqld_safe is a NetWare Loadable Module (NLM) That is transplanted from the original Unix shell script. It runs:
1. Check the system and options.
2. Check the MyISAM table.
3. Keep the MySQL server window.
4. Start and monitor mysqld. Restart if it is terminated due to an error.
5. Send the error message of mysqld to the host_name.err file in the data directory.
6. Send the screen output of mysqld_safe to the host_name.safe file in the data directory.