规划:主要就是data目录和port 端口以及socket 文件路径的差异管理:
配置文件准备
mkdir -p /data/330{6..8}/data
chown -R mysql.mysql /data/*
cat > /data/3306/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/3306/data
socket=/tmp/mysql3306.sock
server_id=6
port=3306
EOF
cat > /data/3307/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/3307/data
socket=/tmp/mysql3307.sock
server_id=7
port=3307
EOF
cat > /data/3308/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/3308/data
socket=/tmp/mysql3308.sock
server_id=8
port=3308
EOF
数据初始化和启动脚本准备
[root@localhost ~]# mkdir -p /data/3306/data /data/3307/data /data/3308/data
[root@localhost ~]# chown -R mysql.mysql /data
数据初始化
[root@localhost ~]# mysqld --defaults-file=/etc/my3306.cnf --initialize-insecure
[root@localhost ~]# mysqld --defaults-file=/etc/my3307.cnf --initialize-insecure
[root@localhost ~]# mysqld --defaults-file=/etc/my3308.cnf --initialize-insecure
启动MySQL
[root@localhost ~]# mysqld_safe --defaults-file=/etc/my3306.cnf &
[root@localhost ~]# mysqld_safe --defaults-file=/etc/my3307.cnf &
[root@localhost ~]# mysqld_safe --defaults-file=/etc/my3308.cnf &
验证
[root@db01 ~]# netstat -tulnp|grep mysqld
tcp6 0 0 :::33060 :::* LISTEN 67933/mysqld
tcp6 0 0 :::3306 :::* LISTEN 67933/mysqld
tcp6 0 0 :::3307 :::* LISTEN 68318/mysqld
tcp6 0 0 :::3308 :::* LISTEN 68498/mysqld
[root@localhost ~]# mysql -S /tmp/mysql3306.sock
[root@localhost ~]# mysql -S /tmp/mysql3307.sock
[root@localhost ~]# mysql -S /tmp/mysql3308.sock