The start and end of MySQL database

Source: Internet
Author: User
Tags mysql in requires socket win32 mysql database
Run Daemon directly


1, you can use the method


General, you can have the following several options to start the MySQL server, their functions and usage is almost the same, so here is a description:


directly uses the MySQL daemon mysqld to start the database system, especially the distribution on the Win32 platform, because server scripts such as Mysql.server are not available on the Win32 platform.


by calling the Safe_mysqld script, it accepts the same parameters as mysqld and tries to determine the correct option for mysqld and then chooses to run it with those.


2, where the script or daemon resides


for the installation of binary distribution, the MYSQLD daemon is installed in the bin directory of the MySQL installation directory, or can be found under the MySQL source code distribution libexec directory, by default/usr/local/libexec/. For RPM distributions, 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 the distribution of UNIX platforms. The Safe_mysqld script is installed in the bin directory of the MySQL installation directory, or can be found in the MySQL source code distribution scripts directory. 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 to use Safe_mysqld script


Safe_mysqld accepts and mysqld the same parameters and attempts to determine the location of the server program and database directory, and then uses these locations to invoke the server. Safe_mysqld redirects the server's standard error output to an error file in the database directory and exists as a record. After the server is started, SAFE_MYSQLD also monitors the server and restarts it when it dies. Safe_mysqld is typically used in the BSD-style version of UNIX.


If you have ever started safe_mysqld for root or in the System launcher, the error log will have root. Calling Safe_mysqld with an unprivileged user identity may cause an error in Access Denied (that is, "ownership denied"). You can delete the error file at this time and try again.


because of the functionality of the Safe_mysqld script, using SAFE_MYSQLD scripts is significantly more effective than starting the mysqld daemon directly.


4, the full process of starting the server


for distribution on UNIX platforms, if you start sqfe_mysqld with root or during system boot, the error log is owned by root, which may cause "permission denied" when you later attempt to invoke Safe_mysqld with a unprivileged user (Permission denied) error, delete error log and try again. Therefore, it is recommended that you first switch to a dedicated user MySQL before starting the server.


specific methods are as follows:


UNIX Platform


$ su MySQL


$ safe_mysql & (or Mysqld &, not recommended)


Win32 Platform


C:/mysql/bin>mysqld--standalone


or C:/Mysql/bin>mysqld-nt–standalone


If you use mysqld and do not install MySQL in a standard location, you usually need to provide the-BASEDIR option for your database installation location.


$safe _mysqld--basedir= "/path/to/mysql" & (Unix platform)


c:/mysql/bin>mysqld--basedir= "X:/path/to/mysql" (Win32 platform)


5, use Safe_mysqld script to implement automatic server startup


Also you can use SAFE_MYSQLD and mysqld to implement the server to start automatically with the operating system. For Linux systems and BSD-style systems (FREEBSD,OPENBSD, etc.), there are usually several files in the/ETC directory that initialize the service at boot time, usually with a name that starts with "RC", and it may be named "Rc.local" Files (or something like that), intentionally used to start a locally installed service.


on such a system, you might add rows like the following to the Rc.local file to start the server (if Safe_mysqld's directory is different on your system, modify it):


if [-x/usr/local/bin/safe_mysqld]; Then/usr/local/bin/safe_mysqld & Fi


because it starts at boot time, the database will be started with root, which can cause problems and trouble at some point. This is the--user option you can specify, 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 script Mysql.server to start shutting down the database


for distribution on UNIX platforms, it is preferable to use database script Mysql.server to start and close the database.


1, mysql.server script storage location

The
mysql.server script is installed in the Share/mysqld directory under the MySQL installation directory or can be found under the MySQL source code distribution support_files directory. For RPM distribution, the script has been renamed MySQL is located in the/ETC/RC.D/INIT.D directory, and there is a replica mysql.server in .... The following discussion is done in the installation for RPM distribution. If you want to use them, you need to copy them to the appropriate directory.


2. How to use the Mysql.server script to start the Stop server


mysql.server scripts can be used to start or stop a server by calling it by using the start or stop arguments:


$ mysql.server Start


$ mysql.server Stop


3, mysql.server function brief


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 nonstandard location, you may need to edit mysql.server. Modify it to run Safe_mysqld before the CD to the correct directory.


4, let mysql.server start the server with a specific user


If you want to run a server as a specific user, you can change the Mysql_daemon_user=root line using other users, you can also modify Mysql.server to pass the other options to Safe_mysqld.


Of course you can also use the option file to provide parameters to the Mysql.server script.


You can also add mysql.server options in 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, use the Mysql.server script to let the server start automatically

The importance of
Mysql.server scripts is that you can use it to configure a database installation that automatically starts with the operating system, which is a common method in a real-world application.


copy Mysql.server to/ETC/RC.D/INIT.D directory:


# CD/ETC/RC.D/INIT.D


# cp/usr/local/mysql/support-files/mysql.server MySQL


then changes its properties 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 manually creating a link:


#cd/etc/rc.d/rc3.d (depending on your level of operation, can be rc5.d)


#ln –s. /init.d/mysql S99mysql


the S99mysql script starts automatically with the start parameter during system startup.


Use the Mysqladmin utility to shut down and restart the database


Daily Maintenance database, often need to shut down or restart the database server. Mysql.server stop can only be used to shut down the database system, and the Mysql.server script starts the server with a specific user identity, so using that textbooks requires superuser privileges. By contrast, mysqladmin is more convenient and suitable for all types of MySQL, platform installation.


shut down the database server


Mysqladmin shutdown


Restart the database server


mysqladmin Reload


Get help


Mysqladmin–help


Mysqladmin utility is very useful, read the help output carefully and you will get more usage.


If the following error occurs:


mysqladmin:connect to server at ' localhost ' failed


error: ' Access denied for User: ' Root@localhost ' (Using password:yes) '


says you need a user who can connect properly, please specify the-U-P option, for example, you can now:


shell>mysqladmin-u root-p shutdown


Enter password:***********


Enter the password you have modified.


to start or stop system services on the NT platform


The above sections describe the way the database server is automatically started on UNIX platforms, while on the Windows (NT) platform you need to install a MySQL server into an NT system for the MySQL database to start automatically.


1, install MySQL as a system service


for NT, the server name is Mysqld-nt.


c:/mysql/bin> mysqld-nt--install


(You can use MYSQLD or mysqld-opt servers on NT, but those cannot start or use Named pipes as a service.) )


2, modify the option 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 option file C:/MY.CNF. Copy the my-example.cnf files in the installation directory to the C packing directory. Modify or add:


[Mysqld]


Basedir = x:/path/to/mysql/


3, how to start and stop the server


you can start and stop the MySQL service with the following command:


NET START MySQL


NET STOP MySQL


Note In this case, you can't use any other option on MYSQLD-NT! You need to use the option file to provide parameters. You can provide the appropriate parameters in the options file.


provides server parameters using the option file


This section describes the more important options that the daemon requires.


for global option files (WINDOWS:C:/MY.CNF or unix:/etc/my.cnf), the more important options are:


user who runs the daemon, if you use Mysql.server, and you specify user in [Mysql.server], then this option is not necessary.


log-update=file Update the log name, which is important for the recovery database, the database server will generate an update log file FILE.N as the name.


-L,--log[=file] Specifies the general log name


--log-bin[=file] Specifies the binary log file to use for server replication.


-SG, the--skip-grant-tables does not load the authorization table at startup and is used for maintenance.


-U,--user=user_name start the UNIX account used by the server


--socket= ... Specifies the UNIX socket file name to use when running multiple servers at the same time.


-P,--port= ... Specifies the port used by the server to use when running multiple servers at the same time. (www.3lian.com)


Summary


as the MySQL administrator, your usual accusation is to ensure that the server as normal as possible, so that the client can access the normal. This chapter discusses how to start and restart, shut down the server, and if you have this capability, you can better maintain the server installation. Most of the methods described in this chapter are suitable for UNIX systems, and readers should carefully distinguish


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.