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=\\u@hostname \\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

注意:新数据库是没有密码的,直接回车即可。