MYSQL的簡單指令碼起停

來源:互聯網
上載者:User

標籤:使用   rtu   複雜   mysql   err   pre   停止   nec   port   

對於多instance安裝的MYSQL來說,起停的過程相對複雜,可以定義一些簡單的指令碼來簡化日常的管理。

1# 環境變數指令碼

[[email protected] scripts]$ cat mysql_env.ini#set envMYSQL_USER=rootMYSQL_PASS=‘password123‘    #明文儲存的密碼,生產庫中當然不可以這樣使用。COPYDIR=‘/opt/mysql‘BASEDIR=‘/data/mysqldata‘#check parameterif [ $# -eq 0 ]then        MYSQL_PORT=3306else        MYSQL_PORT=$1fi[[email protected] scripts]$

2# MYSQL啟動指令碼

[[email protected] scripts]$ cat mysql_startup.sh#!/bin/bashsource /data/mysqldata/scripts/mysql_env.iniecho "Startup MySQL Service: localhost_"${MYSQL_PORT}${COPYDIR}/bin/mysqld_safe --defaults-file=${BASEDIR}/${MYSQL_PORT}/my.cnf &[[email protected] scripts]$

3# MYSQL停止指令碼

[[email protected] scripts]$ cat mysql_shutdown.sh#!/bin/bashsource /data/mysqldata/scripts/mysql_env.iniecho "Shutdown MySQL Service: localhost_"${MYSQL_PORT}${COPYDIR}/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PASS} -S ${BASEDIR}/${MYSQL_PORT}/mysql.sock shutdown[[email protected] scripts]$

4# 快速登陸

[[email protected] scripts]$ cat mysqlcmd.sh#!/bin/bashsource /data/mysqldata/scripts/mysql_env.iniecho "Startup MySQL CMD: localhost_"${MYSQL_PORT}${COPYDIR}/bin/mysql -u${MYSQL_USER} -p${MYSQL_PASS} -S ${BASEDIR}/${MYSQL_PORT}/mysql.sock[[email protected] scripts]$

5# 建立軟串連

[[email protected] scripts]$ pwd/data/mysqldata/scripts[[email protected] scripts]$ ln -s mysqlcmd.sh   mysqlcmd[[email protected] scripts]$ ln -s mysql_startup.sh   mysqlstart [[email protected] scripts]$ ln -s mysql_shutdown.sh   mysqlstop[[email protected] scripts]$ ls -ralttotal 32drwxr-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.inilrwxrwxrwx. 1 mysql mysql    11 Aug 28 20:30 mysqlcmd -> mysqlcmd.shlrwxrwxrwx. 1 mysql mysql    16 Aug 28 20:30 mysqlstart -> mysql_startup.shlrwxrwxrwx. 1 mysql mysql    17 Aug 28 20:31 mysqlstop -> mysql_shutdown.sh

6# 使用過程
6.1# 確定當前運行中的MYSQL執行個體,以連接埠劃分

[[email protected] scripts]$ netstat -lnt | grep 330tcp6       0      0 :::3306                 :::*                    LISTEN

可以看到當前3306正在運行,停止3306
6.2# 停止MYSQL

[[email protected] scripts]$ mysqlstop 3306Shutdown MySQL Service: localhost_3306Warning: Using a password on the command line interface can be insecure.[[email protected] scripts]$

6.3# 啟動MYSQL

[[email protected] scripts]$ mysqlstart 3306Startup MySQL Service: localhost_3306[[email protected] 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[[email protected] scripts]$

6.4# 使用MYSQL

[[email protected] scripts]$ mysqlcmd 3306Startup MySQL CMD: localhost_3306Warning: 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 1Server version: 5.6.31-log Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.([email protected])[(none)]>

MYSQL的簡單指令碼起停

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.