MySQL双主配置_MySQL
安装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
# 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> 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> 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;
三、测试
1、主机A进行一下操作
mysql> use test;
mysql> create table info(
-> id int(10) not null auto_increment primary key,
-> name char(20));
mysql> show tables;
2、主机B进行操作
mysql> use test;
mysql> show tables;
mysql> create table person (
-> id int(20) unsigned not null auto_increment primary key,
-> name char(20));
mysql> show tables;
3.在主机A进行操作检验
上一篇: javascript控制css样式所有样式代码实例汇总
下一篇: php遍历数组的函数及其用法汇总
推荐阅读
-
MySQL-group-replication 配置步骤(推荐)
-
mysql允许远程连接设置(mysql远程访问配置设置技巧)
-
最新mysql-5.7.21安装和配置方法
-
Linux下mysql 5.7 部署及远程访问配置
-
CentOS 7.4 64位安装配置MySQL8.0的详细步骤
-
Linux(Ubuntu)下Mysql5.6.28安装配置方法图文教程
-
win10免安装版本的MySQL安装配置教程
-
Linux(Ubuntu)下mysql5.7.17安装配置方法图文教程
-
mysql 5.7.16 安装配置方法图文教程(ubuntu 16.04)
-
linux下apache、mysql、php安装配置详细笔记