On ArchLinux, we can easily install MySQL. We can use the following command to install:
Pacman-Sv mysql
Just such a simple command, we can install the latest MySQL database on our system. Of course, we need to do the following work to enable the MySQL server.
First, we need to add mysql users and groups. We can do this using the following command:
Groupadd mysql (add mysql Group)
Useradd-g mysql (add a mysql user)
Then we can use the following command to install some predefined MySQL Data Tables:
Mysql_install_db -- user = mysql
At this time, if we start the MySQL server, there will be some prompts, and we will do the following:
Mkdir/var/lib/mysql
Touch/var/lib/mysql/myhost. err
After this operation, we can start the MySQL server:
Mysqld_safe &
MySQL server startup script
Mysqld_safe -- MySQL server startup script
Mysqld_safe is a recommended method for starting a MySQL server on Unix or NetWare systems. Mysqld_safe adds many security features, such as restarting the server when an error occurs and writing the running information to the error log file.
To maintain backward compatibility with the old version of MySQL, the binary release of MySQL also contains safe_mysqld as a link to mysqld_safe. However, we should not rely on this startup program because it will be removed in future versions.
By default, if there is an executable mysqld-max, mysqld_safe
1 in Linux, MySQL-Max RPM depends on the behavior of mysqld_safe. RPM installs an executable program named mysqld-max, which makes mysqld_safe automatically call this executable program.
2. If you have installed a binary release version that contains the mysqld-max server, we will update it to a MySQL without the Max version in a future period, mysqld_safe will still try to run the old mysqld-max server. If we perform such an update, we simply remove the old mysqld-max server and ensure that mysqld_safe runs the new mysqld server.
To overwrite the default behavior and indicate the server we want to run, you can specify a-mysqld or-mysqld-version option for mysqld_safe.
Most of mysqld_safe options are the same as those of mysqld.
Mysqld command line options
All the options specified in the Command Behavior mysqld_safe are passed to mysqld. If you want to use any one that is specified for mysqld_safe and is not supported by mysqld, do not specify them on the command line. Instead, we can list them in an optional file [mysqld_safe] group.
Mysqld_safe reads various options from the [mysqld], [server], and [mysqld_safe] sections of the options file. For backward compatibility, he will also read the [safe_mysqld] section, although we will rename this Part as [mysqld_safe] During MySQL5.0 installation.
Mysqld_safe supports the following options:
-- Help
Displays help information and exits.
-- Autoclose
On the NetWare system, mysqld_safe provides a screen display. When we transport (disable) mysqld_safe NLM, the screen will not disappear by default. On the contrary, they prompt the user to input:
* *
If we want NetWare to automatically close this screen, we can provide the -- autoclose option for mysqld_safe.
-- Basedir = path
MySQL installation directory
-- Core-file-size = size
The size of the core file that mysqld can create. The value of this option will be passed to ulimit-c.
-- Datadir = path
The path of the data directory.
-- Defaults-extra-file = path
The additional option file name to be read outside the regular option file. If you want to specify this option, it must be the first one.
-- Defaults-file = path
Replace the option file to be read from the regular option file. If you want to specify this option, it must be the first one.
-- Ledir = path
Directory path that contains the mysqld program. Use this option to display the location of the specified server.
-- Log-error = path
Write the error log to the specified file.
-- Mysqld = prog_name
The name of the server program to be started. If we use the binary release version of MySQL but use a data directory other than the binary version, this option is required.
-- Mysqld-version = suffix
This option is similar to the -- mysqld program, but we only specify the prefix for the server program. The base name is assumed to be mysqld. For example, if-mysqld-version = max is used, mysqld_safe will start the mysqld-max program in the ledir directory. If the -- mysqld-version parameter is null, mysqld_safe will use the mysqld program in the ledir directory.
-- Nice = priority
Use the nice program to specify a value for the server running level.
-- No-defaults
Does not read any option file. If you want to specify this option, it must be the first one.
-- Open-files-limit = count
The number of files that mysqld can open. This option value will be passed to ulimit-n. Note that if you want to use this option to work properly, you need to start mysqld_safe as root.
-- Pid-file = path
Enter the path of the program ID file.
-- Port = port_num
The port number to be used when listening for TCP/IP connections. The port number must be 1024 or higher, unless MySQL is run as a root user.
-- Skip-character-set-client-handshake
Ignore the character settings sent by the client, and use the default server character settings.
-- Socket = path
The Unix socket file used for local connection.
-- Timezone = zone
Set the TZ time zone environment variable to the specified value. view the operating system file to obtain the detailed format of the legal time zone.
-- User = {user_name | user_id}
Run the mysqld server by user_name or user_id.
When running mysqld_safe, you must first specify the -- defaults-file or -- defaults-extra-option, otherwise the option will not be used. for example, the following command does not use the specified option file:
Mysqld_safe -- port = port_num -- defaults-file = file_name
Instead, we should use the following command:
Mysqld_safe -- defaults-file = file_name -- port = port_num
Write mysqld_safe in this way to ensure normal startup of servers in the source code package or binary release version, even these binary distributions can be started properly when they are installed in different locations. Mysqld_safe requires that one of the following conditions be true:
1. You can find the server and database in the relative directory relative to the mysqld_safe directory. For the binary release version, mysqld_safe searches for the bin and data Directories In its working directory. For MySQL installed in the source code package, it will find the libexec and var directories. If we execute mysqld_safe from our MySQL installation directory, these conditions must be met.
2. If the server and data are not found in the relative directory of the MySQL working directory, mysqld_safe will try to find them in an absolute path. Typical paths are/usr/local/libexec and/usr/local/var. The actual path is determined by the value configured during the build of the binary release version. If MySQL is installed in the path specified during configuration, these must be correct.
Because mysqld_safe will try to find the server and database in the directory relative to its working directory, we can install MySQL anywhere, as long as we execute mysqld_safe In the MySQL installation directory:
Shell> cd mysql_installation_directory
Shell> bin/mysqld_safe &
If mysqld_safe fails, you can specify the -- ledir and -- datadir options for calling in the MySQL installation directory to indicate the directory of the server and database in our system.
In general, we should not modify the mysqld_safe script. We can use the command or the [mysqld_safe] section in the my. cnf option file to modify it. In rare cases, you may have to modify the mysqld_safe script to make it start properly. However, if we do this, if we upgrade in the future, our modified version will be overwritten, so we need to back up a modified version, so that we can reinstall it.
MySQL server shutdown process
The Closing Process of the MySQL server can be summarized as follows:
1. Initialization and Shutdown Process
2. If the server must create a shutdown process
3. The server stops accepting new connections.
4. The server ends the current activity.
5. Storage engine termination or shutdown
6. Server termination
A more detailed description is as follows:
1. Initialization and Shutdown Process
The server can be shut down in several ways. For example, a user with the SHUTDOWN permission can execute the mysqladmin shutdown command. Mysqladmin can run on any platform supported by MySQL. Other operating system-related implementation methods are also possible: On Unix systems, the server ends when the server receives a SIGTERM signal. Servers running as services on Windows can end in task manager.
2. If the server is required, an end process will be created.
Depending on how the initialization ends, the server may create a process to process the end process. If a client request ends, an end process is created. If the end is caused by receiving the SIGTERM signal, the signal process processes the end process, or it creates a separate process for processing. If the server tries to create an end process but fails to create the process, the following error message is displayed:
Error: Can't create thread to kill server
3. The server stops accepting new connections.
To avoid new activities during the end, the server stops receiving new connections. In this way, the network connection of the listener is terminated: TCP/IP Port, Unix socket file, Windows Command pipeline, and shared primary storage on Windows.
4. The server ends the current activity.
For each client-related process, each connection to the client is disconnected and each process is identified as dead. when the process finds that they are identified as such, it will die. the process of null connection will soon die. the current query process will check their status and then die.
For an open transaction process, the transaction will be rolled back. here, we should note that if a process updates a non-transaction table, such as multi-row update or insert operations, partial update of the table will be made, this operation will end before it is completed.
If this server is a master replication server, the processes connecting to the slave server will also be treated as other client processes. that is to say, every process is identified as dead and exits when the current status is checked.
If the server is a slave replication server, the I/O and SQL processes, if active, will be stopped before the client process is identified as dead. the SQL process allows you to end the current statement and then exit. if the SQL process is performing transaction processing at this time, the transaction will be rolled back.
5. Storage engine termination or shutdown
In this step, the data table cache will be refreshed, and all opened tables will be closed.
Each storage engine performs necessary operations on the data tables it manages. For example, MyISAM refreshes the index of a table.
6. The server ends. the transaction will be rolled back. here, we should note that if a process updates a non-transaction table, such as multi-row update or insert operations, partial update of the table will be made, this operation will end before it is completed.
If this server is a master replication server, the processes connecting to the slave server will also be treated as other client processes. that is to say, every process is identified as dead and exits when the current status is checked.
If the server is a slave replication server, the I/O and SQL processes, if active, will be stopped before the client process is identified as dead. the SQL process allows you to end the current statement and then exit. if the SQL process is performing transaction processing at this time, the transaction will be rolled back.
5. Storage engine termination or shutdown
In this step, the data table cache will be refreshed, and all opened tables will be closed.
Each storage engine performs necessary operations on the data tables it manages. For example, MyISAM refreshes the index of a table.
6. The server ends.
(