對執行中的Mysql資料庫建立從庫
所需軟體:
libev-4.15-6.el7.x86_64.rpm
percona-xtrabackup-24-2.4.5-1.el7.x86_64.rpm
首先參考http://blog.itpub.net/28536251/viewspace-2138854/分別在兩節點安裝Mysql。
1、主庫從庫安裝備份軟體
[root@D2-wetestdb160 ~]# yum install -y perl-DBD-MySQL perl-DBI perl-Time-HiRes
[root@D2-wetestdb160 ~]# rpm -ivh libev-4.15-6.el7.x86_64.rpm percona-xtrabackup-24-2.4.5-1.el7.x86_64.rpm
2、主庫備份資料庫
[root@D2-wetestdb160 ~]# mkdir /data/backup
[root@D2-wetestdb160 ~]# innobackupex --user=root --password=123456 /data/backup
[root@D2-wetestdb160 ~]# tar -cvzf mysqlbackup84106_0113.tar.gz /data/backup/2017-01-13_11-17-22/
[root@D2-wetestdb160 ~]# scp mysqlbackup84106_0113.tar.gz root@10.163.89.245:/root
3、從庫進行恢復
[root@D2-stone245 ~]# tar -xvzf mysqlbackup84106_0113.tar.gz -C /var/lib/mysql
[root@D2-stone245 ~]# innobackupex --apply-log /var/lib/mysql/data/backup/2017-01-13_11-17-22/
[root@D2-stone245 ~]# chown -R mysql:mysql /var/lib/mysql/data/backup/2017-01-13_11-17-22
4、從庫修改配置檔案
[root@D2-stone245 ~]# /etc/init.d/mysqld stop
[root@D2-stone245 ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql/data/backup/2017-01-13_11-17-22/
server-id=89254
[root@D2-stone245 ~]# /etc/init.d/mysql.server start
5、從庫配置複製
[root@D2-stone245 ~]# cat /var/lib/mysql/data/backup/2017-01-13_11-17-22/xtrabackup_binlog_info
mysql-bin.000010 100927559
mysql> CHANGE MASTER TO MASTER_HOST='10.163.84.160',MASTER_PORT=3306,MASTER_USER='repl',MASTER_PASSWORD='replsafe',MASTER_LOG_FILE='mysql-bin.000010',MASTER_LOG_POS=100927559;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> set global read_only=1;
Query OK, 0 rows affected (0.00 sec)
mysql> show global variables like "%read_only%";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| innodb_read_only | OFF |
| read_only | ON |
| super_read_only | OFF |
| tx_read_only | OFF |
+------------------+-------+
4 rows in set (0.01 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.163.84.160
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000011
Read_Master_Log_Pos: 1719
Relay_Log_File: D2-stone245-relay-bin.000003
Relay_Log_Pos: 1932
Relay_Master_Log_File: mysql-bin.000011
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: 1719
Relay_Log_Space: 6430
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: 1016384160
Master_UUID: 9ee791f2-ad84-11e6-932d-0050568a6255
Master_Info_File: /var/lib/mysql/data/backup/2017-01-13_11-17-22/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
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
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
libev-4.15-6.el7.x86_64.rpm
percona-xtrabackup-24-2.4.5-1.el7.x86_64.rpm
首先參考http://blog.itpub.net/28536251/viewspace-2138854/分別在兩節點安裝Mysql。
1、主庫從庫安裝備份軟體
[root@D2-wetestdb160 ~]# yum install -y perl-DBD-MySQL perl-DBI perl-Time-HiRes
[root@D2-wetestdb160 ~]# rpm -ivh libev-4.15-6.el7.x86_64.rpm percona-xtrabackup-24-2.4.5-1.el7.x86_64.rpm
2、主庫備份資料庫
[root@D2-wetestdb160 ~]# mkdir /data/backup
[root@D2-wetestdb160 ~]# innobackupex --user=root --password=123456 /data/backup
[root@D2-wetestdb160 ~]# tar -cvzf mysqlbackup84106_0113.tar.gz /data/backup/2017-01-13_11-17-22/
[root@D2-wetestdb160 ~]# scp mysqlbackup84106_0113.tar.gz root@10.163.89.245:/root
3、從庫進行恢復
[root@D2-stone245 ~]# tar -xvzf mysqlbackup84106_0113.tar.gz -C /var/lib/mysql
[root@D2-stone245 ~]# innobackupex --apply-log /var/lib/mysql/data/backup/2017-01-13_11-17-22/
[root@D2-stone245 ~]# chown -R mysql:mysql /var/lib/mysql/data/backup/2017-01-13_11-17-22
4、從庫修改配置檔案
[root@D2-stone245 ~]# /etc/init.d/mysqld stop
[root@D2-stone245 ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql/data/backup/2017-01-13_11-17-22/
server-id=89254
[root@D2-stone245 ~]# /etc/init.d/mysql.server start
5、從庫配置複製
[root@D2-stone245 ~]# cat /var/lib/mysql/data/backup/2017-01-13_11-17-22/xtrabackup_binlog_info
mysql-bin.000010 100927559
mysql> CHANGE MASTER TO MASTER_HOST='10.163.84.160',MASTER_PORT=3306,MASTER_USER='repl',MASTER_PASSWORD='replsafe',MASTER_LOG_FILE='mysql-bin.000010',MASTER_LOG_POS=100927559;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> set global read_only=1;
Query OK, 0 rows affected (0.00 sec)
mysql> show global variables like "%read_only%";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| innodb_read_only | OFF |
| read_only | ON |
| super_read_only | OFF |
| tx_read_only | OFF |
+------------------+-------+
4 rows in set (0.01 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.163.84.160
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000011
Read_Master_Log_Pos: 1719
Relay_Log_File: D2-stone245-relay-bin.000003
Relay_Log_Pos: 1932
Relay_Master_Log_File: mysql-bin.000011
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: 1719
Relay_Log_Space: 6430
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: 1016384160
Master_UUID: 9ee791f2-ad84-11e6-932d-0050568a6255
Master_Info_File: /var/lib/mysql/data/backup/2017-01-13_11-17-22/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
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
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28536251/viewspace-2139007/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Mysql建立資料庫MySql資料庫
- MacOS使用Docker建立MySQL主從資料庫MacDockerMySql資料庫
- MySQL 建立資料庫 建立表MySql資料庫
- 建立資料mysql庫流程MySql
- 執行中請求對應在資料庫和OS中的id資料庫
- 資料庫執行效率的對比測試資料庫
- [Mysql] 4.Mysql 建立資料庫MySql資料庫
- 在 mysql 下 建立新的資料庫和對應的表MySql資料庫
- mysql主庫清理資料,從庫保留MySql
- mysql主從庫執行計劃不同MySql
- 執行緒數目對資料庫的影響執行緒資料庫
- MySQL建立資料庫的兩種方法MySql資料庫
- 多執行緒程式中對資料庫連線使用的疑問執行緒資料庫
- 建立一個MySQL資料庫中的datetime型別MySql資料庫型別
- 【mysql】mysql的資料庫主從(一主一從)MySql資料庫
- PB中建立資料庫的方法資料庫
- 資料庫中主庫和從庫的關係資料庫
- mysql主從資料庫配置MySql資料庫
- [資料庫]MYSQL主從同步資料庫MySql主從同步
- 建立銀行資料庫bankDB資料庫
- mysql建立使用者並且對資料庫授權MySql資料庫
- [MYSQL] 資料庫建立與刪除MySql資料庫
- Lazarus中對mysql資料庫Blob型別進行讀寫例子MySql資料庫型別
- MySQL 資料庫的對庫的操作及其資料型別悔鋒MySql資料庫資料型別
- mysql資料庫的檔案建立方式MySql資料庫
- 建立管理MySQL資料庫的shell指令碼MySql資料庫指令碼
- oracle Mysql PostgreSQL 資料庫的對比OracleMySql資料庫
- 使用RMAN對PDB執行閃回資料庫操作資料庫
- 使用RMAN對CDB執行閃回資料庫操作資料庫
- 從cmd中匯入.SQL檔案並建立資料庫SQL資料庫
- 從資料庫建立一個execl表格資料庫
- 如何建立最簡單的 ABAP 資料庫表,以及編碼從資料庫表中讀取資料 (上)資料庫
- 8、MySQL主從資料庫配置MySql資料庫
- Mysql資料庫主從心得整理MySql資料庫
- Shell指令碼中執行sql語句操作MySQL資料庫的幾個方法指令碼MySql資料庫
- 拜託,在資料庫中執行計算資料庫
- MySQL 5.7從庫system lock執行緒解釋MySql執行緒
- mysql對資料庫表建索引MySql資料庫索引