Xtrabackup实现主从

1)主库备份数据库
[root@localhost mysql_bak]#
innobackupex --user=root --password=P@ss1234 --ibbackup=xtrabackup_56 --socket=/data/mysql_data/mysql.sock --defaults-file=/etc/my.cnf --tmpdir=/data/mysql_bak/tmp /data/mysql_bak/fullbak 2>>/data/mysql_bak/xtra.log
2)scp拷贝到从库
[root@localhost fullbak]# scp -r /data/mysql_bak/fullbak/2015-05-21_18-20-25/ root@1xxx:/home/mysql_bak/fullbak



4)修改从库的my.cnf文件,添加关键配置
其中的相关信息可以在备份文件backup-my.cnf 中查看
[mysqld3306]
user            =mysql
server-id=3306
port            = 3306
socket          =/var/lib/mysql1/mysql.sock
datadir         =/var/lib/mysql1/
log-bin=/var/lib/mysql1/mysql-bin
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
innodb_data_home_dir =/var/lib/mysql1
innodb_data_file_path = ibdata1:2G:autoextend
innodb_log_group_home_dir = /var/lib/mysql1
innodb_log_files_in_group=2
pid_file=/var/lib/mysql1/localhost.localdomain.pid
log_bin_trust_function_creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
5)还原数据库
[root@localhost 2015-05-13_10-46-06]# innobackupex --user=root --password=P@ss1234 --ibbackup=xtrabackup_56 --defaults-file=/home/mysql_bak/3306.cnf --apply-log /home/mysql_bak/fullbak/2015-05-13_10-46-06
[root@localhost 2015-05-13_10-46-06]# innobackupex --user=root --password=P@ss1234 --ibbackup=xtrabackup_56 --defaults-file=/home/mysql_bak/3306.cnf --copy-back  /home/mysql_bak/fullbak/2015-05-13_10-46-06


6)修改文件属主
[root@localhost mysql1]# chown -R mysql:mysql /var/lib/mysql1
[root@localhost mysql1]# chown -R mysql:mysql /var/lib/mysql1
7)启动服务
[root@localhost mysql1]# mysqld_multi start 3306
[root@localhost mysql1]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is running


8)配置主从
[root@localhost 2015-05-13_10-46-06]# cat xtrabackup_binlog_info #查看pos文件及pos点信息 
mysql-bin.000054        120


#设置主从相关信息
mysql> change master to 
    ->      master_host='10.xxxxx',
    ->      master_user='rep_user',
    ->      master_password='P@ss1234',
    ->      master_log_file='mysql-bin.000054',
    ->      master_log_pos=120;
Query OK, 0 rows affected, 2 warnings (0.22 sec)
#启动slave
mysql> start slave
#查看slave状态 
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.4.150
                  Master_User: rep_user
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000054
          Read_Master_Log_Pos: 35218
               Relay_Log_File: localhost-relay-bin.000004
                Relay_Log_Pos: 283
        Relay_Master_Log_File: mysql-bin.000054
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 35218

你可能感兴趣的:(MYSQL)