1、创建多套目录

mkdir -p /data/330{7,8,9}

2、准备多套配置文件

vi /data/3307/my.cnf [mysqld] basedir=/application/mysql datadir=/data/3307 server-id=3307 port=3307 log-bin=/data/3307/mysql-bin socket=/data/3307/mysql.sock log-error=/data/3307/mysql.log

vi /data/3308/my.cnf [mysqld] basedir=/application/mysql datadir=/data/3308 server-id=3308 port=3308 log-bin=/data/3308/mysql-bin socket=/data/3308/mysql.sock log-error=/data/3308/mysql.log

vi /data/3309/my.cnf [mysqld] basedir=/application/mysql datadir=/data/3309 server-id=3309 port=3309 log-bin=/data/3309/mysql-bin socket=/data/3309/mysql.sock log-error=/data/3309/mysql.log

3、初始化多套数据

/application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/data/3307 --user=mysql /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/data/3308 --user=mysql /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/data/3309 --user=mysql

4、启动多个实例

mysqld_safe --defaults-file=/data/3307/my.cnf & mysqld_safe --defaults-file=/data/3308/my.cnf & mysqld_safe --defaults-file=/data/3309/my.cnf &

5、查看启动端口 netstat -lnp |grep 330

6、分别连接测试

mysql -S /data/3307/mysql.sock -e "show variables like 'server_id';" mysql -S /data/3308/mysql.sock -e "show variables like 'server_id';" mysql -S /data/3309/mysql.sock -e "show variables like 'server_id';"