Linux環境下MySQL5.6Master-Slave配置實戰
MySQL的安裝相對於Oracle來說非常簡單,個人覺得與TimesTen的安裝配置更為接近,而且後面的Master-Slave或Master-Master叢集配置更為簡單,甚至比TimesTen的ASP/Active-Active/Active-Standby配置都比TimesTen還要簡單。
Master-Slave搭建步驟:
1、在兩臺主機分別安裝MySQL資料庫軟體
2、在兩臺主機分別建立並初始化MySQL資料庫例項
3、從主庫dump資料(庫)匯入到備庫
4、修改主從(Master-Slave)配置
5、主庫grant、從庫啟動複製(start slave)
6、驗證主備資料同步
--master:
grant replication slave,replication client on *.* to 'slave'@'192.168.100.81' identified by 'slave';
匯出:
flush tables with read lock;
mysql> insert into tony(tid,tdept) values (20001,'ty');
ERROR 1223 (HY000): Can't execute the query because you have a conflicting read lock
mysqldump -uroot -p -E -R -A --databases tyms> /mysql/data/tyms_master.sql
slave匯入:
mysql命令列
mysql>source /mysql/data/tyms_master.sql;
--master:
(root@localhost) [(none)]> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000014 | 594 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
---slave:
change master to master_host='192.168.100.71', master_user='slave', master_password='slave', master_log_file='mysql-bin.000014', master_log_pos=594;
(root@localhost) [(none)]> change master to master_host='192.168.100.71', master_user='slave', master_password='slave', master_log_file='mysql-bin.000014', master_log_pos=594;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
--master:
unlock tables;
---slave:
mysql> start slave;
[tyms]> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.100.71
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000014
Read_Master_Log_Pos: 3051261
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 3050950
Relay_Master_Log_File: mysql-bin.000014
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: 3051261
Relay_Log_Space: 3051123
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: 1000
Master_UUID: 845f69fa-c558-11e5-9462-000c297b003d
Master_Info_File: /mysql/data/mysqldata/mydata/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)
[tyms]> show binlog events in '/mysql/data/mysqldata/mydata/mysql-bin.000014' from 3051261;
[(none)]> select version();
+------------+
| version() |
+------------+
| 5.6.28-log |
+------------+
1 row in set (0.00 sec)
可以看到:Slave_IO_Running | Slave_SQL_Running兩個值都是YES,說明配置成功了。可以在主庫裡執行DML或者DDL驗證下。
如果同步不成功:
1:停掉從庫
mysql> slave stop
2:主庫上找到日誌和位置
mysql> show master status;
(root@localhost) [(none)]> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000014 | 594 | | | |
+------------------+----------+--------------+------------------+-------------------+
3:手動同步
mysql> change master to
> master_host='master_ip',
> master_user='gechong',
> master_password='gechong',
> master_port=3306,
> master_log_file='mysql-bin.000014',
> master_log_pos=594;
1 row in set (0.00 sec)
4:啟動從庫
mysql> slave start;
1 row in set (0.00 sec)
如果有異常需要可執行跳過:
>slave stop;
>SET GLOBAL sql_slave_skip_counter = 1;
>slave start;
Created by Tony.Tang[TangYun]2016.02
----------------------End--------------------------
Master-Slave搭建步驟:
1、在兩臺主機分別安裝MySQL資料庫軟體
2、在兩臺主機分別建立並初始化MySQL資料庫例項
3、從主庫dump資料(庫)匯入到備庫
4、修改主從(Master-Slave)配置
5、主庫grant、從庫啟動複製(start slave)
6、驗證主備資料同步
--master:
grant replication slave,replication client on *.* to 'slave'@'192.168.100.81' identified by 'slave';
匯出:
flush tables with read lock;
mysql> insert into tony(tid,tdept) values (20001,'ty');
ERROR 1223 (HY000): Can't execute the query because you have a conflicting read lock
mysqldump -uroot -p -E -R -A --databases tyms> /mysql/data/tyms_master.sql
slave匯入:
mysql命令列
mysql>source /mysql/data/tyms_master.sql;
--master:
(root@localhost) [(none)]> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000014 | 594 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
---slave:
change master to master_host='192.168.100.71', master_user='slave', master_password='slave', master_log_file='mysql-bin.000014', master_log_pos=594;
(root@localhost) [(none)]> change master to master_host='192.168.100.71', master_user='slave', master_password='slave', master_log_file='mysql-bin.000014', master_log_pos=594;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
--master:
unlock tables;
---slave:
mysql> start slave;
[tyms]> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.100.71
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000014
Read_Master_Log_Pos: 3051261
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 3050950
Relay_Master_Log_File: mysql-bin.000014
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: 3051261
Relay_Log_Space: 3051123
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: 1000
Master_UUID: 845f69fa-c558-11e5-9462-000c297b003d
Master_Info_File: /mysql/data/mysqldata/mydata/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)
[tyms]> show binlog events in '/mysql/data/mysqldata/mydata/mysql-bin.000014' from 3051261;
[(none)]> select version();
+------------+
| version() |
+------------+
| 5.6.28-log |
+------------+
1 row in set (0.00 sec)
可以看到:Slave_IO_Running | Slave_SQL_Running兩個值都是YES,說明配置成功了。可以在主庫裡執行DML或者DDL驗證下。
如果同步不成功:
1:停掉從庫
mysql> slave stop
2:主庫上找到日誌和位置
mysql> show master status;
(root@localhost) [(none)]> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000014 | 594 | | | |
+------------------+----------+--------------+------------------+-------------------+
3:手動同步
mysql> change master to
> master_host='master_ip',
> master_user='gechong',
> master_password='gechong',
> master_port=3306,
> master_log_file='mysql-bin.000014',
> master_log_pos=594;
1 row in set (0.00 sec)
4:啟動從庫
mysql> slave start;
1 row in set (0.00 sec)
如果有異常需要可執行跳過:
>slave stop;
>SET GLOBAL sql_slave_skip_counter = 1;
>slave start;
Created by Tony.Tang[TangYun]2016.02
----------------------End--------------------------
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24930246/viewspace-1988877/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- linux下配置java環境LinuxJava
- linux環境下ssh 互信配置Linux
- Linux 下配置 node + mongodb 環境LinuxMongoDB
- Linux環境下nginx安裝配置LinuxNginx
- Linux環境配置Linux
- DM8 Linux環境下配置ODBCLinux
- Linux下Java環境變數的配置LinuxJava變數
- Linux系統下CUDA和cuDNN環境配置LinuxDNN
- Linux下環境搭建(二)——jenkins+gitlab配置LinuxJenkinsGitlab
- jdk在linux下安裝、配置環境變數JDKLinux變數
- Linux環境下的Android的ADK安裝配置LinuxAndroid
- Linux & Windows 環境下 RabbitMQ 安裝與基本配置LinuxWindowsMQ
- Linux & Windows 環境下 Redis 安裝與基本配置LinuxWindowsRedis
- Linux環境下elasticsearch-6.2.2安裝以及配置LinuxElasticsearch
- Linux環境變數配置Linux變數
- Linux下安裝Python,以及環境變數的配置LinuxPython變數
- CentOS下Ant環境配置CentOS
- Maven環境下MyBatisGenerator 配置MavenMyBatis
- Windows 下 Laravel 環境配置WindowsLaravel
- linux工具配置環境變數Linux變數
- Linux配置環境變數$PATHLinux變數
- Linux環境HBase安裝配置Linux
- linux環境使用Certbot配置httpsLinuxHTTP
- Linux環境Azkaban安裝配置Linux
- 開發環境配置 - Linux(Ubuntu)開發環境LinuxUbuntu
- linux java環境變數配置LinuxJava變數
- 【Linux運維】LNMP環境配置Linux運維LNMP
- Docker 實戰之 CentOS7 系統環境配置DockerCentOS
- 實戰生產環境vCenter HA配置(VCSA6.5)
- LibOpenCM3(一) Linux下命令列開發環境配置Linux命令列開發環境
- 快速搭建 Linux(LNMP + Linux 安裝 + 環境配置)LinuxLNMP
- windows的vscode中配置linux環境WindowsVSCodeLinux
- Linux中Go環境配置和GoModuleLinuxGo
- Linux—Ubuntu14.0.5配置JAVA環境LinuxUbuntuJava
- linux或者CentOS環境下安裝.NET Core環境LinuxCentOS
- Linux下Java環境安裝LinuxJava
- Linux環境下安裝NginxLinuxNginx
- Linux下安裝Go環境LinuxGo
- linux環境下redis安裝LinuxRedis