# #mariadb和mysql Generic Multi-instance script for-server.
VI mdp.sh script content reference content as follows
#!/bin/bash
Echo ' waits for Mariadb-server or mysql-server service software to complete installation '
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 ' Please enter the MySQL instance port number, for example 3306, 3307, etc.: ' X
n=$ (Echo $x |cut-c 4)
NETSTAT-ATUNLP | grep $x
If [$? -eq 0];then
echo "$x instance already exists, no need to create"
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 [e-mail protected] '% ' identified by ' repl '; f Lush privileges; "
Mysql-uroot-p3306-s/data/$x/$x. Sock-e "Grant all on * * to [email protected] '% ' identified by ' admin '; flush privile GES; "
Mysql-uroot-p3306-s/data/$x/$x. Sock-e "show Databases;show Master status;"
}
Fi
Done
Configure the slave server
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
MySQL Multi-instance script