MySQL 5.5 複製搭建流程
--Master 192.168.78.139
--Slave 192.168.78.137
--在Slave安裝好MySQL軟體,安裝流程可以參考原始碼安裝文章
http://blog.itpub.net/26506993/viewspace-2072859/
--Master關閉資料庫,並複製資料檔案到Slave
[root@localhost backup]# /software/bin/mysqladmin -usystem -p'Mysql#2015' shutdown
[root@localhost backup]# 160426 19:50:32 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[1]+ Done /software/bin/mysqld_safe --defaults-file=/etc/my.cnf (wd: /data)
(wd now: /backup)
[root@localhost backup]# ps -ef|grep 3306
root 20319 55613 0 19:50 pts/2 00:00:00 grep 3306
[root@localhost /]# zip -r /install/mysql_data_20160427.zip /data/
[root@localhost install]# scp /install/mysql_data_20160427.zip root@192.168.78.137:/install/
The authenticity of host '192.168.78.137 (192.168.78.137)' can't be established.
RSA key fingerprint is 4a:41:41:4b:4b:83:ea:cc:4b:56:bb:20:0a:8c:88:ce.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.78.137' (RSA) to the list of known hosts.
root@192.168.78.137's password:
mysql_data_20160427.zip 100% 5053KB 4.9MB/s 00:01
--Slave,將傳輸過來的資料檔案解壓到Slave所要使用的資料檔案目錄
[root@localhost install]# mkdir /mysql_data
[root@localhost install]# unzip -d /mysql_data/ /install/mysql_data_20160427.zip
[root@localhost install]# chown -R mysql.mysql /mysql_data/
--編輯Master的配置檔案
[root@localhost install]# vim /etc/my.cnf
# Log
server-id = 100
log-bin = /log/binlog/mysql-bin
--啟動Master的Mysql資料庫
[root@localhost backup]# /software/bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 20592
[root@localhost backup]# 160426 20:32:49 mysqld_safe Logging to '/log/err.log'.
160426 20:32:49 mysqld_safe Starting mysqld daemon with databases from /data
--在Master資料庫上面建立複製專用賬戶
mysql> grant replication slave on *.* to 'repl'@'192.168.78.%' identified by 'Mysql#2015';
Query OK, 0 rows affected (0.04 sec)
--檢視Master當前的日誌名稱和位置,用於下面在Slave的change master to命令
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.000008 | 256 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
--配置Slave的配置檔案
[root@localhost data]# vim /etc/my.cnf
# Log
server-id = 200
log-bin = /log/binlog/mysql-bin
relay-log = /log/binlog/mysqld-relay-bin
relay-log-index = /log/binlog/product-mysql-relay-index
datadir = /mysql_data/data
--啟動Slave的資料庫服務
[root@localhost mysql]# /data/bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 22611
[root@localhost mysql]# 160426 22:53:18 mysqld_safe Logging to '/log/err.log'.
160426 22:53:18 mysqld_safe Starting mysqld daemon with databases from /mysql_data/data
--在Slave配置Slave到Master的連線
透過CHANGE MASTER TO語句來設定Slave連線到Master伺服器的引數,來使Slave讀取Master的二進位制日誌和Slave的relay日誌。
mysql> change master to
-> master_host='192.168.78.139',
-> master_port=3306,
-> master_user='repl',
-> master_password='Mysql#2015',
-> master_log_file='mysql-bin.000008',
-> master_log_pos=256;
Query OK, 0 rows affected (0.16 sec)
引數含義:
master_host 指定連線的Master主機
master_port 指定連線的Master的埠
master_user 指定連線的Master的複製專用賬戶
master_password 指定連線的Master的複製專用賬戶的密碼
master_log_file Master當前的日誌名稱
master_log_pos Master當前的日誌位置
--Master釋放全域性只讀鎖
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
--檢視Slave的狀態
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.78.139
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000008
Read_Master_Log_Pos: 256
Relay_Log_File: mysqld-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000008
Slave_IO_Running: No
Slave_SQL_Running: No
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: 256
Relay_Log_Space: 107
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: NULL
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: 0
1 row in set (0.00 sec)
--啟用Slave的應用日誌服務
START SLAVE語句會啟動兩個執行緒。I/O執行緒會從Master伺服器讀取事件並將它們存放到relay log中。SQL執行緒會從relay log中讀取事件並執行它們。執行START SLAVE需要SUPER許可權。
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
--Slave日誌中的內容
[root@localhost data]# tailf /log/err.log
160427 5:57:08 [Note] 'CHANGE MASTER TO executed'. Previous state master_host='', master_port='3306', master_log_file='', master_log_pos='4'. New state master_host='192.168.78.139',
master_port='3306', master_log_file='mysql-bin.000010', master_log_pos='107'.
160427 5:57:23 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000010' at position 107, relay log '/log/binlog/mysqld-relay-bin.000001' position: 4
160427 5:57:25 [Note] Slave I/O thread: connected to master 'repl@192.168.78.139:3306',replication started in log 'mysql-bin.000010' at position 107
--Slave 192.168.78.137
--在Slave安裝好MySQL軟體,安裝流程可以參考原始碼安裝文章
http://blog.itpub.net/26506993/viewspace-2072859/
--Master關閉資料庫,並複製資料檔案到Slave
[root@localhost backup]# /software/bin/mysqladmin -usystem -p'Mysql#2015' shutdown
[root@localhost backup]# 160426 19:50:32 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[1]+ Done /software/bin/mysqld_safe --defaults-file=/etc/my.cnf (wd: /data)
(wd now: /backup)
[root@localhost backup]# ps -ef|grep 3306
root 20319 55613 0 19:50 pts/2 00:00:00 grep 3306
[root@localhost /]# zip -r /install/mysql_data_20160427.zip /data/
[root@localhost install]# scp /install/mysql_data_20160427.zip root@192.168.78.137:/install/
The authenticity of host '192.168.78.137 (192.168.78.137)' can't be established.
RSA key fingerprint is 4a:41:41:4b:4b:83:ea:cc:4b:56:bb:20:0a:8c:88:ce.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.78.137' (RSA) to the list of known hosts.
root@192.168.78.137's password:
mysql_data_20160427.zip 100% 5053KB 4.9MB/s 00:01
--Slave,將傳輸過來的資料檔案解壓到Slave所要使用的資料檔案目錄
[root@localhost install]# mkdir /mysql_data
[root@localhost install]# unzip -d /mysql_data/ /install/mysql_data_20160427.zip
[root@localhost install]# chown -R mysql.mysql /mysql_data/
--編輯Master的配置檔案
[root@localhost install]# vim /etc/my.cnf
# Log
server-id = 100
log-bin = /log/binlog/mysql-bin
--啟動Master的Mysql資料庫
[root@localhost backup]# /software/bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 20592
[root@localhost backup]# 160426 20:32:49 mysqld_safe Logging to '/log/err.log'.
160426 20:32:49 mysqld_safe Starting mysqld daemon with databases from /data
--在Master資料庫上面建立複製專用賬戶
mysql> grant replication slave on *.* to 'repl'@'192.168.78.%' identified by 'Mysql#2015';
Query OK, 0 rows affected (0.04 sec)
--檢視Master當前的日誌名稱和位置,用於下面在Slave的change master to命令
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.000008 | 256 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
--配置Slave的配置檔案
[root@localhost data]# vim /etc/my.cnf
# Log
server-id = 200
log-bin = /log/binlog/mysql-bin
relay-log = /log/binlog/mysqld-relay-bin
relay-log-index = /log/binlog/product-mysql-relay-index
datadir = /mysql_data/data
--啟動Slave的資料庫服務
[root@localhost mysql]# /data/bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 22611
[root@localhost mysql]# 160426 22:53:18 mysqld_safe Logging to '/log/err.log'.
160426 22:53:18 mysqld_safe Starting mysqld daemon with databases from /mysql_data/data
--在Slave配置Slave到Master的連線
透過CHANGE MASTER TO語句來設定Slave連線到Master伺服器的引數,來使Slave讀取Master的二進位制日誌和Slave的relay日誌。
mysql> change master to
-> master_host='192.168.78.139',
-> master_port=3306,
-> master_user='repl',
-> master_password='Mysql#2015',
-> master_log_file='mysql-bin.000008',
-> master_log_pos=256;
Query OK, 0 rows affected (0.16 sec)
引數含義:
master_host 指定連線的Master主機
master_port 指定連線的Master的埠
master_user 指定連線的Master的複製專用賬戶
master_password 指定連線的Master的複製專用賬戶的密碼
master_log_file Master當前的日誌名稱
master_log_pos Master當前的日誌位置
--Master釋放全域性只讀鎖
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
--檢視Slave的狀態
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.78.139
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000008
Read_Master_Log_Pos: 256
Relay_Log_File: mysqld-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000008
Slave_IO_Running: No
Slave_SQL_Running: No
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: 256
Relay_Log_Space: 107
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: NULL
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: 0
1 row in set (0.00 sec)
--啟用Slave的應用日誌服務
START SLAVE語句會啟動兩個執行緒。I/O執行緒會從Master伺服器讀取事件並將它們存放到relay log中。SQL執行緒會從relay log中讀取事件並執行它們。執行START SLAVE需要SUPER許可權。
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
--Slave日誌中的內容
[root@localhost data]# tailf /log/err.log
160427 5:57:08 [Note] 'CHANGE MASTER TO executed'. Previous state master_host='', master_port='3306', master_log_file='', master_log_pos='4'. New state master_host='192.168.78.139',
master_port='3306', master_log_file='mysql-bin.000010', master_log_pos='107'.
160427 5:57:23 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000010' at position 107, relay log '/log/binlog/mysqld-relay-bin.000001' position: 4
160427 5:57:25 [Note] Slave I/O thread: connected to master 'repl@192.168.78.139:3306',replication started in log 'mysql-bin.000010' at position 107
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2089700/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 5.5 主主複製搭建流程MySql
- MySQL 5.5級聯複製配置流程MySql
- MySQL 5.5使用Xtrabackup線上搭建複製環境MySql
- redhat 5.5 配置 mysql AB複製RedhatMySql
- mysql5.5半同步複製探究MySql
- 配置mysql5.5主從複製、半同步複製、主主複製MySql
- mysql5.5中的半同步複製MySql
- MySQL 5.5 常用的複製環境管理命令MySql
- MySQL5.5半同步複製實現原理MySql
- mysql主從複製搭建MySql
- Mysql的複製原理以及流程MySql
- MySQL 5.5 Semi-sync 半同步複製測試MySql
- MySQL 5.5半同步複製的配置與監控MySql
- MySQL 5.7搭建多源複製MySql
- MySQL 複製介紹及搭建MySql
- MYSQL主從複製的搭建MySql
- MYSQL主主複製的搭建MySql
- MySQL5.7主從複製-半同步複製搭建MySql
- MySQL 5.5.x 配置Master-Slave主從複製MySqlAST
- MySQL 主從複製的執行流程MySql
- Mysql主從複製原理及搭建MySql
- 簡單搭建MySQL主從複製MySql
- 【Mysql】Mysql5.7的多源複製搭建MySql
- MySQL 5.5 原始碼安裝流程MySql原始碼
- mysql主從複製的理解和搭建MySql
- mysql 5.7 主從複製搭建及原理MySql
- docker-compase搭建mysql主從複製DockerMySql
- MySQL 5.7.17 Group Relication(組複製)搭建手冊MySql
- Mysql 5.6庫級表級複製的搭建MySql
- MySQL搭建帶過濾的複製環境MySql
- mysql 主從複製搭建詳細步驟MySql
- 生產環境搭建MySQL複製的教程MySql
- MySQL 5.5複製升級到5.7的一點簡單嘗試MySql
- MySQL(14)---Docker搭建MySQL主從複製(一主一從)MySqlDocker
- MySQL複製MySql
- MySQL 複製MySql
- mysql複製--主從複製配置MySql
- MySQL 5.7 基於GTID搭建主從複製MySql