MySQL Multi-instance script

Source: Internet
Author: User

# #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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.