對於多instance安裝的MYSQL來講,起停的過程相對複雜,能夠定義一些簡單的腳原本簡化平常的管理。mysql
1# 環境變量腳本sql
[mysql@mysql01 scripts]$ cat mysql_env.ini #set env MYSQL_USER=root MYSQL_PASS='password123' #明文保存的密碼,生產庫中固然不能夠這樣使用。 COPYDIR='/opt/mysql' BASEDIR='/data/mysqldata' #check parameter if [ $# -eq 0 ] then MYSQL_PORT=3306 else MYSQL_PORT=$1 fi [mysql@mysql01 scripts]$
2# MYSQL啓動腳本bash
[mysql@mysql01 scripts]$ cat mysql_startup.sh #!/bin/bash source /data/mysqldata/scripts/mysql_env.ini echo "Startup MySQL Service: localhost_"${MYSQL_PORT} ${COPYDIR}/bin/mysqld_safe --defaults-file=${BASEDIR}/${MYSQL_PORT}/my.cnf & [mysql@mysql01 scripts]$
3# MYSQL中止腳本tcp
[mysql@mysql01 scripts]$ cat mysql_shutdown.sh #!/bin/bash source /data/mysqldata/scripts/mysql_env.ini echo "Shutdown MySQL Service: localhost_"${MYSQL_PORT} ${COPYDIR}/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PASS} -S ${BASEDIR}/${MYSQL_PORT}/mysql.sock shutdown [mysql@mysql01 scripts]$
4# 快速登錄ide
[mysql@mysql01 scripts]$ cat mysqlcmd.sh #!/bin/bash source /data/mysqldata/scripts/mysql_env.ini echo "Startup MySQL CMD: localhost_"${MYSQL_PORT} ${COPYDIR}/bin/mysql -u${MYSQL_USER} -p${MYSQL_PASS} -S ${BASEDIR}/${MYSQL_PORT}/mysql.sock [mysql@mysql01 scripts]$
5# 創建軟鏈接code
[mysql@mysql01 scripts]$ pwd /data/mysqldata/scripts [mysql@mysql01 scripts]$ ln -s mysqlcmd.sh mysqlcmd [mysql@mysql01 scripts]$ ln -s mysql_startup.sh mysqlstart [mysql@mysql01 scripts]$ ln -s mysql_shutdown.sh mysqlstop [mysql@mysql01 scripts]$ ls -ralt total 32 drwxr-xr-x. 5 mysql mysql 44 Aug 27 03:33 .. -rwxrw-r--. 1 mysql mysql 189 Aug 28 20:14 mysql_startup.sh -rwxrw-r--. 1 mysql mysql 220 Aug 28 20:19 mysql_shutdown.sh -rwxrw-r--. 1 mysql mysql 202 Aug 28 20:23 mysqlcmd.sh -rw-r--r--. 1 mysql mysql 12288 Aug 28 20:26 .mysql_shutdown.sh.swp -rw-rw----. 1 mysql mysql 176 Aug 28 20:26 mysql_env.ini lrwxrwxrwx. 1 mysql mysql 11 Aug 28 20:30 mysqlcmd -> mysqlcmd.sh lrwxrwxrwx. 1 mysql mysql 16 Aug 28 20:30 mysqlstart -> mysql_startup.sh lrwxrwxrwx. 1 mysql mysql 17 Aug 28 20:31 mysqlstop -> mysql_shutdown.sh
6# 使用過程
6.1# 肯定當前運行中的MYSQL實例,以端口劃分ip
[mysql@mysql01 scripts]$ netstat -lnt | grep 330 tcp6 0 0 :::3306 :::* LISTEN
能夠看到當前3306正在運行,中止3306
6.2# 中止MYSQLinput
[mysql@mysql01 scripts]$ mysqlstop 3306 Shutdown MySQL Service: localhost_3306 Warning: Using a password on the command line interface can be insecure. [mysql@mysql01 scripts]$
6.3# 啓動MYSQLcmd
[mysql@mysql01 scripts]$ mysqlstart 3306 Startup MySQL Service: localhost_3306 [mysql@mysql01 scripts]$ 180828 21:33:49 mysqld_safe Logging to '/data/mysqldata/3306/data/../mysql-error.log'. 180828 21:33:49 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data [mysql@mysql01 scripts]$
6.4# 使用MYSQLit
[mysql@mysql01 scripts]$ mysqlcmd 3306 Startup MySQL CMD: localhost_3306 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.31-log Source distribution Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. (root@localhost)[(none)]>