4、设置mysql多实例启动脚本:
(1)3306:
[root@backup application]# cat /data/3306/mysql
#!/bin/sh
. /etc/init.d/functions
export PATH=/application/mysql/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
MYUSER="root"
MYPASS="123456"
MYADMIN="mysqladmin -u$MYUSER -p$MYPASS -S /data/3306/mysql.sock"
MYPID="/data/3306/mysqld.pid"

[ $UID -eq 0 ] || {
echo "please use root"
exit 1
}

function usage (){
echo "USAGE:sh $0 |start|stop|restart|"
}

RETVAL=0
function check() {
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
action "$1" /bin/true
else
action "$1" /bin/false
fi
}

function start() {
if [ -f $MYPID ]; then
echo "mysql is running......"
else
3306/my.cnf &>/dev/null &
check "start mysql"
fi
}

function stop() {
if [ -f $MYPID ]; then
$MYADMIN shutdown &>/dev/null
check "stop mysql"
else
echo "mysql is stop......"
fi
}

function main(){
if [ $# -eq 1 ]; then
case "$1" in
start)
start
sleep 2
;;
stop)
stop
sleep 2
;;
restart)
stop
start
;;
*)
usage
;;
esac
else
usage
fi
}

main $*
[root@backup application]# chmod u+x /data/3306/mysql
(2)3307:
3307启动脚本和3306的启动脚本一致,将3306启动脚本中的路径改为3307的路径即可;
[root@backup application]# chmod u+x /data/3307/mysql
(3)目录树:
[root@backup application]# tree /data
/data
├── 3306
│ ├── data
│ ├── my.cnf
│ └── mysql
└── 3307
├── data
├── my.cnf
└── mysql
4 directories, 4 files

5、配置mysql多实例的权限:
[root@backup application]# chown -R mysql:mysql /data/3306/
[root@backup application]# chown -R mysql:mysql /data/3307/
6、初始化mysql多实例:
[root@backup application]# cd /application/mysql/scripts/
[root@backup scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data/ --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
[root@backup scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data/ --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
7、启动mysql多实例:
[root@backup scripts]# cd /application/
[root@backup application]# /data/3306/mysql start
start mysql [确定]
[root@backup application]# /data/3307/mysql start
start mysql [确定]
[root@backup application]# netstat -tunlp | egrep "3306|3307"
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 7827/mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 7475/mysqld