##mariadb和mysql-server的通用多实例脚本。
vi mdp.sh 脚本内容参考内容如下
#!/bin/bash
echo ‘等待mariadb-server或mysql-server服务软件安装完毕‘
while true
do
yum install -y mariadb-server mariadb &>/dev/null
yum install -y mysql-server mysql &>/dev/null
netstat -atunlp| grep 330
read -p ‘请输入MYSQL实例端口号,例如3306、3307等:‘ x
n=$(echo $x|cut -c 4)
netstat -atunlp | grep $x
if [ $? -eq 0 ];then
echo "$x实例已存在,无需再创建"
else {
mkdir -pv /data/$x
chown -Rv mysql.mysql /data
mysql_install_db --datadir=/data/$x --user=mysql
#y="/data/$x/$x"
cat > /data/$x/$x.cnf <<EOF
[mysqld_multi]
mysqld=/usr/bin/mysqld_safe
mysqladmin=/usr/bin/mysqladmin
[mysqld$x]
user=mysql
port=$x
socket=/data/$x/$x.sock
pid-file=/data/$x/$x.pid
log-error=/data/$x.log
datadir=/data/$x
max_connections=200
default-storage-engine=innodb
character_set_server=utf8
server-id=$n
log-bin=/data/$x/mysql-bin
EOF
mysqld_multi --defaults-file=/data/$x/$x.cnf start $x
#mysqld_multi --defaults-file=/data/$x/$x.cnf stop $x
sleep 3s
mysqld_multi --defaults-file=/data/$x/$x.cnf report
netstat -atunlp| grep 330
mysql -uroot -P3306 -S /data/$x/$x.sock -e "grant replication slave on *.* to repl@‘%‘ identified by ‘repl‘;flush privileges;"
mysql -uroot -P3306 -S /data/$x/$x.sock -e "grant all on *.* to admin@‘%‘ identified by ‘admin‘;flush privileges;"
mysql -uroot -P3306 -S /data/$x/$x.sock -e "show databases;show master status;"
}
fi
done
配置从服务器
mysql -uadmin -padmin -h 192.168.100.6 -P3307
CHANGE MASTER TO MASTER_HOST=‘192.168.100.6‘,MASTER_USER=‘repl‘,MASTER_PASSWORD=‘repl‘,MASTER_PORT=3306,MASTER_LOG_FILE=‘mysql-bin.000001‘,MASTER_LOG_POS=106;
start slave;
show slave status\G
原文地址:http://1364952.blog.51cto.com/1354952/1952217