MySQL的主从同步+mysql-zrm备份
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> grant replication slave on *.* to 'backup'@'192.168.10.52' identified by 'backuppwd';
Query OK, 0 rows affected (0.00 sec)
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 | 265 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
3、打包主库迁移数据
[root@db1 mysql-5.1.63]# cd /usr/local/mysql/
[root@db1 mysql]# tar -zcf data0708.tar.gz ./data/
三、Slave配置
安装过程如上,步骤省略......
[root@db2 mysql-5.1.63]# vim /usr/local/mysql/my.cnf #修改server-id
server-id = 2
将主数据库备份数据拷贝过来并解压到相应的目录
[root@db2 mysql-5.1.63]# mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
[root@db2 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.63-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> change master to master_host='192.168.10.51',master_user='backup',master_password='backuppwd',master_log_file='mysql-bin.000002',master_log_pos=265;
Query OK, 0 rows affected (0.24 sec)
mysql> start slave;
Query OK, 0 rows affected (0.02 sec)
mysql> show slave status\G
......
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
......
四、验证
1、在Master上面操作
[root@db1 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock
mysql> create database mysqltest;
Query OK, 1 row affected (0.00 sec)
mysql> use mysqltest;
Database changed
mysql> create table user (id int(5),name char(10));
Query OK, 0 rows affected (0.00 sec)
mysql> insert into user values (0001,'xieping');
Query OK, 1 row affected (0.00 sec)
mysql> insert into user values (0002,'huxinxin');
Query OK, 1 row affected (0.00 sec)
mysql> insert into user values (0003,'dingpeng');
Query OK, 1 row affected (0.00 sec)
2、在Slave上操作
[root@db2 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| mysqltest |
| test |
+--------------------+
4 rows in set (0.02 sec)
mysql> select id,name from mysqltest.user;
+------+----------+
| id | name |
+------+----------+
| 1 | xieping |
| 2 | huxinxin |
| 3 | dingpeng |
+------+----------+
3 rows in set (0.00 sec)