標籤:多執行個體
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多執行個體添加一個執行個體