MySQL系列之D-2------MySQL多執行個體添加一個執行個體

來源:互聯網
上載者:User

標籤:多執行個體

D-2.1   添加一個執行個體(3309執行個體)

D-2.1.1、建立目錄

# cd /data

# mkdir 3309/data

D-2.1.2、建立my.cnf檔案在/data/3309

[client]

port=3309

socket=/data/3309/mysql.sock

prompt=\\[email protected] \\r:\\m:\\s->

[mysqld]

basedir =/mysql

datadir =/data/3309/data

port =3309

server_id =4

socket =/data/3309/mysql.sock

log-bin=/data/3309/mysql_bin

binlog_format=mixed

#binlog-do-db=

#binlog-ignore-db=

long_query_time=1

relay-log=/data/3309/relay_bin

relay-log-info-file=/data/3309/relay_log.info

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]

log-error=/data/3309/mysql_err.log

pid-file=/data/3309/mysql_pid.pid

D-2.1.3、建立mysql檔案(啟動指令碼)

#!/bin/bash

############################################################

#this scripts is created by liuweixinat 2015-06-18

#liuweixin QQ:1433203077

############################################################

 

#init

port=3309

mysql_user="root"

mysql_pwd="oracle"

CmdPath="/mysql/bin"

mysql_sock="/data/${port}/mysql.sock"

#startup function

function_start_mysql()

{

    if[ ! -e "$mysql_sock" ];then

       printf"Starting MySQL...\n"

       /bin/sh${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null &

    else

       printf"MySQL is running...\n"

       exit

    fi

}

 

#stop function()

function_stop_mysql()

{

    if[ ! -e "$mysql_sock" ];then

           printf"Stoping MySQL...\n"

           exit

    else

           printf  "Stoping Mysql...\n"

           ${CmdPath}/mysqladmin-u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown

    fi

}

 

#restart function

function_restart_mysql()

{

    printf"Restarting MySQL...\n"

    function_stop_mysql

    sleep2

    function_start_mysql

}

   

#function_kill_mysql()

#{

#   kill-9 $(ps -ef | grep ‘bin/mysqld_safe‘ | grep ${mysql_port} | awk ‘{printf $2}‘)

#   kill-9 $(ps -ef | grep ‘libexec/mysqld‘ | grep ${mysql_port} | awk ‘{printf $2}‘)

#}

   

case $1 in

start)

    function_start_mysql;;

stop)

    function_stop_mysql;;

#kill)

# function_kill_mysql;;

restart) 

    function_restart_mysql;;

*)

    printf"Usage:/data/${port}/mysql {start|stop|restart}\n"

esac

D-2.1.4、啟動服務

# /data/3309/mysql start

注意:在這裡通過netstat -lnt 330,是沒有辦法看到3309進程的

D-2.1.5、登入3309執行個體

# mysql -h 127.0.0.1 -uroot -p--port=3309

# mysql -uroot -p -S/data/3309/mysql.sock

注意:新資料庫是沒有密碼的,直接斷行符號即可。

本文出自 “技術博” 部落格,謝絕轉載!

MySQL系列之D-2------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.