[Shell] MySQL Start-Stop script

Source: Internet
Author: User
Tags stop script

Wrote a more complete MySQL multi-instance start stop script.

[[email protected] 3307]#Cat MySQL#!/bin/sh[ $#! = 1]&&{Echo"usage:/data/3307/mysql {start|stop}"Exit 0}if[" $"=="Start"];thenif[!-f/data/3307/mysqld.pid];then/application/mysql/bin/mysqld_safe--defaults-file=/data/3307/my.cnf 2>&1 >/dev/null &Sleep5Echo"starting MySQL ..."    ElseEcho"MySQL is running already!"fielif[" $"=="Stop"];thenif[-f/data/3307/mysqld.pid];then/application/mysql/bin/mysqladmin-s/data/3307/mysql.sock-uroot-p123456 shutdown 2>&1 >/dev/null &Echo"stoping MySQL ..."    ElseEcho"MySQL is Stopped already!"Fifi

Note the point:

1.mysql is placed in the/data/3307/directory with Execute permissions

2, the script commands the full path, for example

   /application/mysql/bin/mysqladmin

3, determine whether a file exists or not

Presence: [-f/data/3307/mysqld.pid];

does not exist: [!-f/data/3307/mysqld.pid];

4, string comparison Note: 4.1 Double quotes 4.2 equal spaces on both sides, and = = 4.3[] spaces on both sides

["$" = = "Stop" ]

[Shell] MySQL Start-Stop script

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.