MySQL双主数据库_[数据库]MySQL双主配置

[数据库]MySQL双主配置

0

2015-11-15 23:00:03

MySQL双主配置

准备环境:服务器操作系统为RHEL6.4 x86_64,为最小化安装。主机A和主机B均关闭防火墙和SELINUX ,IP地址分别为192.168.131.129和192.168.131.130,MySQL版本为5.6.26,为通用二进制包。安装MySQL

1.主机A操作

# tar xf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

# mv mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysql

# useradd -M -s /sbin/nologin mysql

# chown -R root:root /usr/local/mysql/*

# chown -R mysql:mysql /usr/local/mysql/data/

# yum -y install libaio

# cd /usr/local/mysql/scripts/

# ./mysql_install_db --datadir=/usr/local/mysql/data/ --user=mysql --basedir=/usr/local/mysql/

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

# echo 'export PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile

# source /etc/profile

# vim /etc/my.cnf

[mysqld]

datadir=/usr/local/mysql/data

socket=/tmp/mysql.sock

user=mysql

symbolic-links=0

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

# service mysqld start

#chkconfig mysqld on

# ss -tunlp | grep 3306

bc91bb04e6e9c61e24c974e4440db8f2.gif

# mysqladmin -uroot password '123456' #设置数据库密码

2.主机B操作(同上)

二、配置双主

1、主机A操作

# vim /etc/my.cnf

server-id=20

log-bin=mysql-bin

log-bin-index=mysql-bin.index

replicate-ignore-db=test

binlog-ignore-db=mysql

binlog-ignore-db=information_schema

auto-increment-increment=2

auto-increment-offset=1

# service mysqld restart

# mysql -uroot -p123456

mysql> flush tables with read lock;

再打开一个远程终端窗口,执行以下操作

# mysqldump -uroot -p123456 -B test > test.sql

返回之前的终端窗口,做以下操作

mysql> unlock tables;

mysql> grant replication slave on *.* to 'wdd'@'192.168.131.130' identified by '123456';

mysql> flush privileges;

# scp test.sql 192.168.131.130:/root

2、主机B操作

# vim /etc/my.cnf

server-id = 21

log-bin=mysql-bin

log-bin-index= mysql-bin.index

replicate-do-db=test

binlog-ignore-db=mysql

binlog-ignore-db=information_schema

auto-increment-increment=2

auto-increment-offset=2

#service mysqld restart

# mysql -uroot -p123456 < test.sql

# mysql -uroot -p123456

mysql> grant replication slave on *.* to 'wdd'@'192.168.131.129' identified by '123456';

mysql> flush privileges;

3.主机A和主机B分别作如下操作

主机A

①# mysql -uroot -p123456

mysql> SHOW MASTER STATUS;

bc91bb04e6e9c61e24c974e4440db8f2.gif

mysql> change master to

master_host='192.168.131.130',

master_user='wdd',

master_password='123456',

master_log_file=' mysql-bin.000002',

master_log_pos=420;

mysql> start slave;

mysql> show slave status\G;

bc91bb04e6e9c61e24c974e4440db8f2.gif

②# mysql -uroot -p123456

mysql> show master status;

bc91bb04e6e9c61e24c974e4440db8f2.gif

mysql> change master to

master_host='192.168.131.129',

master_user='wdd',

master_password='123456',

master_log_file='mysql-bin.000002',

master_log_pos=689;

mysql> start slave;

mysql> show slave status\G;

bc91bb04e6e9c61e24c974e4440db8f2.gif

三、测试

1、主机A进行一下操作

mysql> use test;

mysql> create table info(

-> id int(10) not null auto_increment primary key,

-> name char(20));

mysql> show tables;

bc91bb04e6e9c61e24c974e4440db8f2.gif

2、主机B进行操作

mysql> use test;

mysql> show tables;

bc91bb04e6e9c61e24c974e4440db8f2.gif

mysql> create table person (

-> id int(20) unsigned not null auto_increment primary key,

-> name char(20));

mysql> show tables;

bc91bb04e6e9c61e24c974e4440db8f2.gif

3.在主机A进行操作检验

bc91bb04e6e9c61e24c974e4440db8f2.gif

本文网址:http://www.shaoqun.com/a/159422.html

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:admin@shaoqun.com。

MYSQL

0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值