MySQL automatic start using the configuration file/etc/My. CNF

Source: Internet
Author: User

Generally, you can startMysqldServer:

?Direct callMysqld. This method is suitable for any platform.

?Run the MySQL server as a Windows service. It can be implemented in the supported Windows versions (such as NT, 2000, XP, and 2003. You can set the service to automatically start the server when Windows is started, or manually start the service as needed. For more information, see section 2.3.12 "Start MYSQL as a Windows service ".

?CallMysqld_safe, Can beMysqldConfirm the correct options and use these options for running. This script is applicable to bsd unix-based systems. See section 5.1.3, "mysqld_safe: MySQL server startup script ".

?CallMySQL. Server. This script is mainly used to start and close the system running directory using System V-style. It is usually installed under MySQL.MySQL. ServerScript callMysqld_safeTo start the server. See section 5.1.4, "mysql. SERVER: MySQL server startup script ".

?You can install a separate MySQL startup Item installation package on Mac OS X to enable the system to automatically start MySQL at startup. Startup Item callMySQL. ServerTo start the server. For details, see section 2.5, "Install MySQL on Mac OS X ".

MySQL. ServerAndMysqld_safeScript and Mac OS X startup item can be used to manually start the server or automatically start the system.MySQL. ServerAnd startup Item can also be used to stop the server.

The MySQL. server script can be used to start or stop a server. It is called by using the start or stop parameters:

 
Shell>MySQL. Server start
 
Shell>MySQL. server stop

InMySQL. ServerBefore starting the server, it changes the directoryMySQLInstall the directory, and then callSafe_mysqld. If you want to run the server as a specific user, in the/etc/My. CNF option file [Mysqld] Add the corresponding user option to the Group, as shown later in this section. (If you have a binary distribution version installed in a non-standard location, you may need to edit it.MySQL. Server. Modify it and runSafe_mysqldCD to the correct directory. Note that if you modifyMySQL. Server, Then upgrade at some timeMySQLYour modified version will be overwritten, so you should make a copy of the edited version that you can reinstall ).

MySQL. server stopStop it by sending a signal to the server. You can manually executeMysqladmin ShutdownDisable the server.

To automatically start and stop MySQL on the server"/Etc/rc *Add the start and stop commands in the appropriate places in the file.

If you use Linux Server RPM to install the package (MySQL-server-VERSION.rpm ),MySQL. ServerThe script is installed in the/etc/init. d directory named MySQL. You do not need to install it manually. For details about the Linux RPM package, see Section 2.4, "Install MySql in Linux ".

The names of startup scripts for RPM packages installed by some vendors are different, for exampleMysqld.

If it is not automatically installedMySQL. ServerTo install MySQL, You can manually install it. You can find the script in the MySQL installation directory or in the support-Files directory of the MySQL source code tree.

To manually installMySQL. Server, With nameMySQLCopy it to the/etc/init. d directory and change it to an executable file. You only need to change the locationMySQL. ServerIs is located and the corresponding directory for executing these commands:

 
Shell>CP mysql. Server/etc/init. d/MySQL
 
Shell>Chmod + x/etc/init. d/MySQL

The old Red Hat system uses the/etc/rc. d/init. d directory instead of the/etc/init. d directory. Call the command before the node. You can also create a symbolic connection to/etc/rc. d/init. d:

 
Shell>CD/etc
 
Shell>Ln-s rc. d/init. d.

After the script is installed, it depends on your operating system. In Linux, you can use chkconfig:

 
Shell>Chkconfig -- addmysql

In some Linux systems, the following command is also required to fully activate the MySQL script:

 
Shell>Chkconfig -- level 345 MySQL on

In FreeBSD, the startup script is usually located in/usr/local/etc/rc. d /. On the RC (8) page of the manual, the script is executed only when the basic name of the script in this directory matches *. shshell file name mode. Other files or directories in the directory will be ignored. In other words, in FreeBSD, the mysql. server script should be installed as/usr/local/etc/rc. d/MySQL. server. Sh for automatic start.

In another case set above, some operating systems also use/etc/rc. Local or/etc/init. d/boot. Local to start other services at startup. To start MySQL using this method, you can append a command to the corresponding Startup file:

 
/Bin/sh-C 'CD/usr/local/MySQL;./bin/mysqld_safe -- user = MySQL &'

For other systems, check the operating system documentation to see how to install the startup script.

You can also"/Etc/My. CNF"File addedMySQL. Server. A typical"/Etc/My. CNF"The file may look like this:

 
[Mysqld]
 
Datadir =/usr/local/MySQL/var
 
Socket =/var/tmp/MySQL. Sock
 
Port = 3306
 
User = MySQL
 
 
 
[MySQL. Server]
 
Basedir =/usr/local/MySQL

The MySQL. server script uses the following variables: basedir, datadir, and PID-file. After definition, they must be placed in the option file, not in the command line.MySQL. ServerOnly the Start and Stop command line parameters are identified.

The following table shows the option group that the server and each STARTUP script read from the option file:

Script

Quota Group

Mysqld

[Mysqld], [server], [mysqld-Major-version]

MySQL. Server

[Mysqld], [mysql. Server], [server]

Mysqld_safe

[Mysqld], [server], [mysqld_safe]

[Mysqld-Major-Version] means a group named [mysqld-5.0] For version5.0.xAnd 5.1.x. This feature can be used to specify the option to be read by the server of the given release series.

For backward compatibility,MySQL. ServerAlso read the [mysql_server] group,Mysqld_safeRead the [safe_mysqld] group. However, when using MySQL 5.1, you should update the option file and use the [mysql. Server] and [mysqld_safe] groups.

See section 4.3.2 "Use Option Files ".

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.