《Mysql入門MySQL 主從同步部分數據表》要點:
本文介紹了Mysql入門MySQL 主從同步部分數據表,希望對您有用。如果有疑問,可以聯系我們。
MYSQL入門主服務器IP:192.168.1.100 從服務器IP:192.168.1.101
MYSQL入門在配置MySQL主從同步的時候需要保證一下幾點:
MYSQL入門1、更改主服務器MySQL配置文件,/etc/my.cnf
,檢查二進制日志log-bin是否開啟了,把server-id設置為1
MYSQL入門
[mysqld]
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
MYSQL入門2、創建一個從服務器鏈接主服務器的帳號 (1)、在命令行下登錄mysql:
MYSQL入門
# mysql -uroot -p
MYSQL入門(2)、首先創建一個名為:slave_user,密碼為:987654321的帳號
MYSQL入門
mysql> grant replication slave on *.* to 'slave_user'@‘192.168.1.%’ identified by '987654321';
Query OK, 0 rows affected (0.52 sec)
MYSQL入門(3)、查看二進制日志的信息,記錄下當前的二進制文件名稱和位置:
MYSQL入門
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 508296
Server version: 5.5.48-log Source distribution
Copyright (c) 2000, 2016, 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> show master status;
+------------------+-----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+-----------+--------------+------------------+
| mysql-bin.000019 | 864074260 | | |
+------------------+-----------+--------------+------------------+
1 row in set (0.00 sec)
MYSQL入門(4)、對數據庫進行鎖表操作,防止我們在導出數據的時候還有數據寫入,然后導出我們需要的數據表,再把數據表導入到從服務器去
MYSQL入門
mysql> unlock tables;
mysql> Ctrl-C -- exit!
Aborted
[root@192 ~]# mysqldump -uroot -p******** erp claim_staff>claim_staff.sql;
MYSQL入門1、更改從服務器MySQL配置文件,/etc/my.cnf
,檢查二進制日志log-bin是否開啟了,把server-id設置為為一個的一個id(推薦設置成服務器的最后一組數字)
MYSQL入門
[mysqld]
server-id = 101
#我們再改變一些二進制日志文件的名稱(可選)
log-bin=mysql-relay-bin
replicate-do-table=erp.claim_staff
2、配置同步參數: 參數說明: | 參數 | 說明 |
---|---|---|
MASTER_HOST | 主服務器IP地址 | |
MASTER_PORT | 主服務器端口 | |
MASTER_USER | 主服務器用戶名 | |
MASTER_PASSWORD | 主服務器密碼 | |
MASTER_LOG_FILE | 主服務器當前binlog文件(前面我們獲取到“mysql-bin.000019”) | |
MASTER_LOG_POS | 主服務器當前binlog文件的位置(就是我們前面獲取到的Position的值:864074260) |
MYSQL入門
mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.249',MASTER_USER='slave_user',MASTER_PASSWORD='987654321',MASTER_LOG_FILE='mysql-bin.000019',MASTER_LOG_POS=865765533;
Query OK, 0 rows affected (0.11 sec)
MYSQL入門3、啟動同步進程,然后檢查狀態
MYSQL入門
#啟動同步進程
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
#檢查狀態
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.100
Master_User: slave_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000019
Read_Master_Log_Pos: 873059878
Relay_Log_File: 192-relay-bin.000002
Relay_Log_Pos: 7294598
Relay_Master_Log_File: mysql-bin.000019
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table: erp.claim_staff
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 873059878
Relay_Log_Space: 7294752
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: 1
1 row in set (0.00 sec)
ERROR:
No query specified
MYSQL入門這么多信息中,我們只需要看2項,只要為YES即可,分別是:
MYSQL入門
Slave_IO_Running: Yes # 去主庫讀二進制日志,然后保存到從庫去
Slave_SQL_Running: Yes # 將中繼日志轉換成為SQL語句執行
MYSQL入門4、到這里,主從同步指定的表也完成了.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/5584.html