码迷,mamicode.com
首页 > 数据库 > 详细

Mysql-主从精简配置

时间:2015-08-19 17:38:35      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:mysql-主从配置

                              主从配置      

一、

 

A主机IP192.168.1.84

B主机IP192.168.1.85

 

1、数据库分配权限给从服

 

mysql>GRANT REPLICATION SLAVE ON *.* TO ‘backup’@’192.168.1.85‘ IDENTIFIED BY ‘123456’;

赋予从机权限,有多台丛机,就执行多次

2
打开主机Amy.cnf,输入

server-id               = 1    #
主机标示,整数
log_bin                 = /var/log/mysql/mysql-bin.log   #
确保此文件可写  此步骤可以不用
read-only              =0  #
主机,读写都可以     此步骤可以不用
binlog-do-db         =test   #
需要备份数据,多个写多行
binlog-ignore-db    =mysql #
不需要备份的数据库,多个写多行  此步骤可以不用

 

------------------------------------------------------------------

 

[mysqld]

port = 3306

socket = /tmp/mysql.sock

 

basedir = /data/apps/mysql

datadir = /data/mysql/data

pid-file = /data/mysql/data/mysql.pid

user = mysql

bind-address = 0.0.0.0

server-id = 1

log-bin =/data/mysql/data/mysql-bin.log

binlog-do-db =test

binlog-do-db =ping1

binlog-do-db =ping2

log_bin_trust_function_creators=1

 

数据库备份过从库

mysql> flush tables with read lock;

Query OK, 0 rows affected (0.19 sec)

之后是mysqldump

mysqldump -h127.0.0.1 -p3306 -uroot -p test > /home/chenyz/test.sql

最好在主数据库备份完毕,恢复写操作

mysql> unlock tables;

3
、打开从机Bmy.cnf,输入

server-id               = 2

进入mysql

Stop Slave;

 

Change master to
master_host     =’192.168.110.84’,
master_user     =’backup’,
master_password     =’123456’,
master_port     =3306,

 

Master_log_file =’fileid’,

Master_log_pos=pos;

binlog-do-db =test

binlog-ignore-db =test 忽略某个库的操作写进二进制日志中。

---------------------------------------------------------------------

 

change master to master_host =‘192.168.1.84‘;

change master to master_user =‘backup‘;

change master to master_password=‘123456‘;

change master to master_port =3306;

change master to master_log_file=‘mysql-bin.000006‘;

change master to master_log_pos=214;

 

Start Slave;

 

 

从服my.conf配置文件:
master-connect-retry=60 #
如果从服务器发现主服务器断掉,重新连接的时间差()
replicate-do-db =test #
只复制某个库
replicate-ignore-db=mysql #
不复制某个库


---------------------------------------------------------------------

[mysqld]

port = 3306

socket = /tmp/mysql.sock

 

basedir = /data/apps/mysql  #数据库安装目录

datadir = /data/mysql/data  #数据库data目录

pid-file = /data/mysql/data/mysql.pid

user = mysql

bind-address = 0.0.0.0

server-id = 2

log-bin =/data/mysql/data/mysql-bin.log

replicate-do-db =test

replicate-do-db =ping1

replicate-do-db =ping2

replicate-do-db =dbadsys

log_bin_trust_function_creators=1


4
、同步数据库

主从库都启动即可自动同步,如果不嫌麻烦的话可以把主库的内容导出成SQL,然后在从库中运行一遍

5
、先重启主机Amysql,再重启从机Bmysql

6
、验证

在主机A中,mysql>show master status\G;
              File: mysql-bin.000007

         Position: 130702

     Binlog_Do_DB: test,ping1,ping2

 Binlog_Ignore_DB:

Executed_Gtid_Set:
在从机B中,mysql>show slave status\G;

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 192.168.1.84

                  Master_User: backup

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000007

          Read_Master_Log_Pos: 130702

               Relay_Log_File: mysql-relay-bin.000005

                Relay_Log_Pos: 130865

        Relay_Master_Log_File: mysql-bin.000007

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB: test,ping1,ping2

         在打印出来的状态下,查看以下两个参数的值:

 

         Slave_IO_Running: Yes

 

         Slave_SQL_Running: Yes


 

到此你已经可以使用了!

 


本文出自 “SQL” 博客,请务必保留此出处http://7476463.blog.51cto.com/7466463/1685870

Mysql-主从精简配置

标签:mysql-主从配置

原文地址:http://7476463.blog.51cto.com/7466463/1685870

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!