Home Database Mysql Tutorial MySQL双主配置_MySQL

MySQL双主配置_MySQL

May 30, 2016 pm 05:10 PM

准备环境:服务器操作系统为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

MySQL双主配置_MySQL

# 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

 

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

MySQL双主配置_MySQL

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;

 

②# mysql -uroot -p123456

 

mysql> show master status;

MySQL双主配置_MySQL

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;

MySQL双主配置_MySQL

三、测试

 

1、主机A进行一下操作

 

mysql> use test;

 

mysql> create table info(

 

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

 

-> name char(20));

 

mysql> show tables;

MySQL双主配置_MySQL

2、主机B进行操作

 

mysql> use test;

 

mysql> show tables;

MySQL双主配置_MySQL

mysql> create table person (

 

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

 

-> name char(20));

 

mysql> show tables;

MySQL双主配置_MySQL

3.在主机A进行操作检验
MySQL双主配置_MySQL


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Reduce the use of MySQL memory in Docker Reduce the use of MySQL memory in Docker Mar 04, 2025 pm 03:52 PM

Reduce the use of MySQL memory in Docker

How do you alter a table in MySQL using the ALTER TABLE statement? How do you alter a table in MySQL using the ALTER TABLE statement? Mar 19, 2025 pm 03:51 PM

How do you alter a table in MySQL using the ALTER TABLE statement?

How to solve the problem of mysql cannot open shared library How to solve the problem of mysql cannot open shared library Mar 04, 2025 pm 04:01 PM

How to solve the problem of mysql cannot open shared library

What is SQLite? Comprehensive overview What is SQLite? Comprehensive overview Mar 04, 2025 pm 03:55 PM

What is SQLite? Comprehensive overview

Run MySQl in Linux (with/without podman container with phpmyadmin) Run MySQl in Linux (with/without podman container with phpmyadmin) Mar 04, 2025 pm 03:54 PM

Run MySQl in Linux (with/without podman container with phpmyadmin)

Running multiple MySQL versions on MacOS: A step-by-step guide Running multiple MySQL versions on MacOS: A step-by-step guide Mar 04, 2025 pm 03:49 PM

Running multiple MySQL versions on MacOS: A step-by-step guide

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? Mar 18, 2025 pm 12:00 PM

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?

See all articles