关于mysql的备份方案2 A-B复制
建立A B复制之前要做好以下几步
1. 把主重的mysql 的user, group 的id 都设成27
2. 时间同步
ntpdate
3. 两边的数据要一样,能够正常启动
将主的/data (数据存放目录)里的内容拷贝到从机子去或者两边都初始化一次数据;
4. 两台机能ping 通 主:10.1.1.4 从:10.1.1.2
配置主服务器my.cnf 10.1.1.4
必须有
log-bin=XXXX
server-id=XXX
-----------------------参考我自己的
[mysqld]
port=3306
datadir=/data
socket=/var/run/mysqld/mysql5.socket
pid-file=/var/run/mysqld/mysql5.pid
general-log-file=/var/log/mysqld/mysql5.log
log-error=/var/log/mysqld/mysql5-error.log
log-bin=101
server-id=201
[client]
socket=/var/run/mysqld/mysql5.socket
-------------------------------------
从服务器my.cnf 10.1.1.2
server-id=2
master-host=10.1.1.4
master-user=alex
master-password=123
------------------------------- 参考我自己的
[mysqld]
port=3306
datadir=/data
socket=/var/run/mysqld/mysql5.socket
pid-file=/var/run/mysqld/mysql5.pid
general-log-file=/var/log/mysqld/mysql5.log
log-error=/var/log/mysqld/mysql5-error.log
server-id=2
master-host=10.1.1.4
master-user=tt
master-password=123
[client]
socket=/var/run/mysqld/mysql5.socket
-------------------------------
在主mysql服务器:
mysql> grant super, replication slave on *.* to 'alex'@'%' identified by '123';
mysql> flush tables with read lock; 锁定数据库写入
mysql> show master status; 查询当前二进制日志信息
+------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------+----------+--------------+------------------+
| 101.000001 | 638 | | |
+------------+----------+--------------+------------------+
1 row in set (0.00 sec)
===============================
在从服务器运行
slave (76,92)
mysql> stop slave;
mysql> change master to
master_host='10.1.1.4',
master_port=3306,
master_user='alex',
master_password='123',
master_log_file='101.000001',
master_log_pos=638;
mysql> start slave;
如果出现找不到master.info 就在从的/data/下新建一个 touch master.info
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.1.1.4
Master_User: alex
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: 101.000001
Read_Master_Log_Pos: 5304
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 245
Relay_Master_Log_File: 101.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
注意:下面两个必须是yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
=================================================
验证:
在主服务器新建1个表,插入信息让后再看看从的有没有及时更新。
mysql>UNLOCK TABLES; 解锁