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