In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "the method of starting and terminating MySQL database". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Because the MySQL server has a variety of installation and distribution, and can run on a variety of operating platforms, so it has a variety of ways to start and stop. You can use one of them according to the actual situation. When you install, upgrade, or maintain the system, you may need to start and terminate the server multiple times, and you need to know all aspects of starting and terminating the server.
Run the daemon directly
1. Methods that you can use
In general, you can choose to start the MySQL server with the following options, and their functions and usage are almost the same, so let's introduce them here:
Start the database system directly using the MySQL daemon mysqld, especially the distribution on the Win32 platform, because there are no server scripts such as mysql.server available on the Win32 platform.
By calling the safe_mysqld script, it takes the same parameters as mysqld, tries to determine the right options for mysqld, and then chooses which ones to run it with.
2. The location of the script or daemon
For binary distribution installations, the mysqld daemon is installed in the bin directory of the MySQL installation directory, or can be found in the libexec directory of the MySQL source code distribution, which defaults to / usr/local/libexec/. For rpm distribution, the mysqld should be in the program search path determined by the PATH variable, so it can be referenced directly.
Safe_mysqld is still a script and exists only in distributions on the Unix platform. The safe_mysqld script is installed in the bin directory of the MySQL installation directory, or can be found in the scripts directory where the MySQL source code is distributed. For rpm distribution, the script should be in the program search path determined by the PATH variable, so it can be referenced directly.
3. Why use safe_mysqld script
Safe_mysqld takes the same parameters as mysqld and tries to determine the location of the server program and database directories, and then uses these locations to invoke the server. Safe_mysqld redirects the standard error output of the server to an error file in the database directory and exists as a record. After starting the server, safe_mysqld also monitors the server and restarts it when it crashes. Safe_mysqld is commonly used in BSD-style versions of Unix.
If you have ever started safe_mysqld for root or in the system startup program, the error log will be owned by root. If safe_mysqld is called again as an unprivileged user, it may cause a "Access Denied" (that is, "ownership denied") error. At this point, you can delete the error file and try again.
Because of the power of safe_mysqld scripts, using safe_mysqld scripts is obviously more effective than starting the mysqld daemon directly.
4. The complete process of starting the server
For distribution on the Unix platform, if you start sqfe_mysqld with root or during system boot, the error log is owned by root, which may cause a "permission denied" error when you try to call safe_mysqld with a non-privileged user later. Delete the error log and try again. Therefore, it is recommended that you switch to a dedicated user mysql before starting the server.
The specific methods are as follows:
Unix platform
$su mysql
$safe_mysql & (or mysqld &, not recommended)
Win32 platform
C: mysqlin > mysqld-- standalone
Or C: mysqlin > mysqld-nt-standalone
If you use mysqld and do not install mysql in a standard location, you usually need to provide the-basedir option where your database is installed.
$safe_mysqld-- basedir= "/ path/to/mysql" & (Unix platform)
C:mysqlin > mysqld-- basedir= "x:/path/to/mysql" (Win32 platform)
5. Realize the automatic startup of the server by using safe_mysqld script
You can also use safe_mysqld and mysqld to enable the server to start automatically with the operating system. For systems and BSD-style systems (FreeBSD,OpenBSD, etc.), there are usually several files under the / etc directory that initialize the service at boot, usually with the name "rc", and it is possible that a file named "rc.local" (or something like that) is specifically used to start the locally installed service.
On such a system, you might add a line similar to the following to the rc.local file to start the server (if the safe_mysqld directory is different on your system, modify it):
If [- x / usr/local/bin/safe_mysqld]; then / usr/local/bin/safe_mysqld & fi
Because this starts at boot time, the database will be started with root identity, which may cause problems and hassles at some point. This is what you can specify-- user option, so you can change the above code to:
If [- x / usr/local/bin/safe_mysqld]; then
/ usr/local/bin/safe_mysqld-user=mysql-datadir=/path/to/data &
Fi
Use the script mysql.server to start and shut down the database
For distribution on the Unix platform, a better approach is to use the database script mysql.server to start and shut down the database.
1. The location of the mysql.server script
The mysql.server script is installed in the share/mysqld directory under the MySQL installation directory or can be found in the support_files directory where the MySQL source code is distributed. For rpm distribution, the script has been renamed mysql in the / etc/rc.d/init.d directory and in … . There is a copy of mysql.server in. The following discussion is done in the installation for the RPM distribution. If you want to use them, you need to copy them to the appropriate directory.
2. How to start and stop the server using mysql.server script
The mysql.server script can be used to start or stop the server by calling it with the start or stop parameter:
$mysql.server start
$mysql.server stop
3. A brief description of the functions of mysql.server.
Before mysql.server starts the server, it changes the directory to the MySQL installation directory and then calls safe_mysqld. If you have a binary distribution installed in a non-standard location, you may need to edit mysql.server. Modify it to cd to the correct directory before running safe_mysqld.
4. Let mysql.server start the server with a specific user
If you want to run the server as a specific user, you can change the mysql_daemon_user=root exercise to other users, or you can modify mysql.server to pass other options to safe_mysqld.
Of course, you can also use the options file to provide parameters to the mysql.server script.
You can also add the mysql.server option to a global "/ etc/my.cnf" file. A typical "/ etc/my.cnf" file might look like this:
[mysqld]
Datadir=/usr/local/mysql/var
Socket=/tmp/mysqld.sock
Port=3306
[mysql.server]
User=mysql
Basedir=/usr/local/mysql
The mysql.server script uses the following variables: user, datadir, basedir, bindir, and pid-file.
5. Let the server start automatically by using mysql.server script
The importance of the mysql.server script is that you can use it to configure a database installation that starts automatically with the operating system, which is a common method in a real system.
Copy mysql.server to the / etc/rc.d/init.d directory:
# cd / etc/rc.d/init.d
# cp / usr/local/mysql/support-files/mysql.server mysql
Then change its attribute to "x" (executable, executable)
# chmod + x mysql
Finally, run chkconfig to add MySQL to your system's startup service group.
# / sbin/chkconfig-del mysql
# / sbin/chkconfig-add mysql
You can also do this by setting up links manually:
# cd / etc/rc.d/rc3.d (can be rc5.d depending on your runlevel)
# ln-s.. / init.d/mysql S99mysql
During system startup, the S99mysql script starts automatically using the start parameter.
Shut down and restart the database using the mysqladmin utility
Daily maintenance of the database often requires shutting down or restarting the database server. Mysql.server stop can only be used to shut down the database system, which is not convenient, and the mysql.server script starts the server with a specific user identity, so using this script requires the privileges of the superuser. By contrast, mysqladmin is much more convenient and suitable for installation of all types and platforms of MySQL.
Shut down the database server
Mysqladmin shutdown
Restart the database server
Mysqladmin reload
Get help
Mysqladmin-help
The mysqladmin utility is very useful, and if you read the help output carefully, you will get more usage.
If the following error occurs:
Mysqladmin: connect to server at localhost failed
Error: Access denied for user: (Using password: YES)
Indicates that you need a user who can connect normally, please specify the-u-p option, for example, you can now:
Shell > mysqladmin-u root-p shutdown
Enter Password:*
Just enter the password you have changed.
Start or stop system services on the NT platform
The above sections describe how to enable the database server to start automatically on the Unix platform, while on the (NT) platform in order for MySQL to start automatically, you need to install the MySQL server as a service of the NT system.
1. Install MySQL as a system service
For NT, the server name is d-nt.
C:mysqlin > mysqld-nt-- install
You can use mysqld or mysqld-opt servers on NT, but those cannot be started as a service or use named pipes. )
2. Modify the options file
If your mysql does not have the default location c:mysql installed, it cannot be started because the database will not be able to determine the location of the database directory. In this case, you need to provide a global options file c:my.cnf. Copy the my-example.cnf file from the installation directory to the root directory of disk c. To modify or add:
[mysqld]
Basedir = x:/path/to/mysql/
3. The method of starting and stopping the server
You can start and stop the MySQL service with the following command:
NET START mysql
NET STOP mysql
Note that in this case, you cannot use any other options with mysqld-nt! You need to use the options file to provide parameters. You can provide the appropriate parameters in the options file.
Use the options file to provide parameters for the server
This section describes the more important options required by the daemon.
For global options files (windows:c:/my.cnf or unix:/etc/my.cnf), the more important options are:
User users running daemons, if you use mysql.server and specify user in [mysql.server], then this option is not necessary.
The log-update=file update log name is important for restoring the database, and the database server will generate an update log file with the name file.n.
-l,-- log [= fil
This is the end of the content of "the method of starting and terminating MySQL database". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.