【MySQL Database】数据库复制--Replication

[root@wallet01 ~]# wget https://repo.percona.com/yum/percona-release-latest.noarch.rpm
[root@wallet01 ~]# rpm -ivh percona-release-latest.noarch.rpm
[root@wallet01 ~]# yum install -y percona-xtrabackup-24

[root@wallet01 ~]# vi /etc/my.cnf
[mysqld]
server_id = 1
log_bin = mysql-bin
binlog_format = row
sync_binlog = 1
binlog_cache_size = 16M
max_binlog_cache_size = 4G
max_binlog_size = 128M
expire_logs_days = 7

[root@wallet01 ~]# su - mysql
[mysql@wallet01 ~]$ ssh-keygen
[mysql@wallet01 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub mysql@wallet02
[mysql@wallet01 ~]$ ssh wallet02 date
Mon Feb 18 10:41:16 CST 2019

[root@wallet01 ~]# mysql -uroot -p
Enter password: 
mysql> create user xtrabackup@‘localhost‘ identified by ‘xtrabackup‘;
Query OK, 0 rows affected (0.10 sec)

mysql> grant reload,lock tables,replication client,process on *.* to xtrabackup@‘localhost‘;
Query OK, 0 rows affected (0.02 sec)

mysql> grant replication slave on *.* to ‘repl‘@‘192.168.40.%‘ identified by ‘repl‘;
Query OK, 0 rows affected (0.11 sec)

mysql> flush privileges; 
Query OK, 0 rows affected (0.05 sec)

流式,远程,压缩备份
[mysql@wallet01 ~]$ xtrabackup --backup --user=xtrabackup --password=xtrabackup --stream=tar | ssh mysql@wallet02 \ "gzip >/home/mysql/backup/`date ‘+%Y-%m-%d_%H-%M-%S‘`.tar.gz"
[root@wallet02 ~]# wget https://repo.percona.com/yum/percona-release-latest.noarch.rpm
[root@wallet02 ~]# rpm -ivh percona-release-latest.noarch.rpm
[root@wallet02 ~]# yum install -y percona-xtrabackup-24

[root@wallet02 ~]# vi /etc/my.cnf
[mysqld]
server_id = 2
master_info_repository = table
relay_log_info_repository = table
relay_log = relay-bin
relay_log_recovery = 1

[root@wallet02 ~]# su - mysql
[mysql@wallet02 ~]$ cd backup
[mysql@wallet02 backup]$ tar izxvf 2019-02-18_10-42-09.tar.gz 
[mysql@wallet02 backup]$ ls -lh
total 1.6G
-rw-rw-r-- 1 mysql mysql 515M Feb 18 10:43 2019-02-18_10-42-09.tar.gz
-rw-rw---- 1 mysql mysql  423 Feb 18 10:43 backup-my.cnf
-rw-rw---- 1 mysql mysql 1.0G Feb 18 10:42 ibdata1
drwxrwxr-x 2 mysql mysql 4.0K Feb 18 10:47 mysql
drwxrwxr-x 2 mysql mysql 4.0K Feb 18 10:47 performance_schema
drwxrwxr-x 2 mysql mysql 4.0K Feb 18 10:47 soe
-rw-rw---- 1 mysql mysql  10M Feb 18 10:42 undo001
-rw-rw---- 1 mysql mysql  10M Feb 18 10:42 undo002
-rw-rw---- 1 mysql mysql  10M Feb 18 10:42 undo003
-rw-rw---- 1 mysql mysql   27 Feb 18 10:43 xtrabackup_binlog_info
-rw-rw---- 1 mysql mysql  121 Feb 18 10:43 xtrabackup_checkpoints
-rw-rw---- 1 mysql mysql  490 Feb 18 10:43 xtrabackup_info
-rw-rw---- 1 mysql mysql  21M Feb 18 10:43 xtrabackup_logfile

[mysql@wallet02 backup]$ cat xtrabackup_binlog_info
mysql-bin.000226        101300289

[mysql@wallet02 ~]$ xtrabackup --prepare --target-dir=/home/mysql/backup
[mysql@wallet02 ~]$ xtrabackup --copy-back --target-dir=/home/mysql/backup

[root@wallet02 ~]# service mysqld start
Logging to ‘/var/lib/mysql/wallet02.err‘.
Starting mysqld:                                           [  OK  ]

[mysql@wallet02 ~]$ mysql -uroot -pabcd.1234
mysql> change master to master_host=‘192.168.40.34‘, master_user=‘repl‘, master_password=‘repl‘, master_log_file=‘mysql-bin.000226‘, master_log_pos=101300289;
Query OK, 0 rows affected, 2 warnings (0.05 sec)

mysql> start slave;
Query OK, 0 rows affected (0.03 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.40.34
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000228
          Read_Master_Log_Pos: 5518995
               Relay_Log_File: relay-bin.000008
                Relay_Log_Pos: 5519158
        Relay_Master_Log_File: mysql-bin.000228
             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: 5518995
              Relay_Log_Space: 5519372
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 201
                  Master_UUID: b23f4533-2e78-11e9-91e4-000c296e09c1
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
1 row in set (0.00 sec)

 

【MySQL Database】数据库复制--Replication

上一篇:js函数实现转换css中常用的颜色编码


下一篇:Jquery对回复者添加匿名评论选项