mysql master or master copy
生活随笔
收集整理的這篇文章主要介紹了
mysql master or master copy
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
雙主復制:在兩臺server配置my.cnf
[root@localhost mysql]# egrep -v "^$|^#" /etc/my.cnf
datadir = /mydata/data
skip_name_resolve = ON
innodb_file_per_table = ON
relay-log = relay-log
auto-increment-offset = 1 表示自增長字段從那個數開始,他的取值范圍是1 .. 65535
auto-increment-increment = 2 表示自增長字段每次遞增的量,其默認值是1,取值范圍是1 .. 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 1兩臺server配置文件幾乎一樣,只需要指定auto-increment-offset = 1為偶數或者奇數;在每臺server創(chuàng)建可復制的用戶和密碼如下:在192.168.8.200創(chuàng)建用戶:
MariaDB [(none)]> grant replication slave,replication client ON *.* to 'glq'@'192.168.%.%' identified by '123123';
Query OK, 0 rows affected (0.01 sec)MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 245 |
| mysql-bin.000002 | 28799 |
| mysql-bin.000003 | 1069459 |
| mysql-bin.000004 | 500 |
+------------------+-----------+
4 rows in set (0.00 sec)
MariaDB [(none)]> change master to master_host='192.168.8.201',master_user='glq1',master_password='123123',master_log_file='mysql-bin.000004',master_log_pos=501;
Query OK, 0 rows affected (0.07 sec)MariaDB [(none)]> slave start-> ;
Query OK, 0 rows affected (0.07 sec)
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.8.201Master_User: glq1Master_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000004Read_Master_Log_Pos: 593Relay_Log_File: relay-log.000002Relay_Log_Pos: 621Relay_Master_Log_File: mysql-bin.000004Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 593Relay_Log_Space: 909Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_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: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 2
1 row in set (0.00 sec)在192.168.8.201創(chuàng)建用戶:
MariaDB [(none)]> grant replication slave,replication client on *.* to 'glq1'@'192.168.%.%' identified by '123123';
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 245 |
| mysql-bin.000002 | 28799 |
| mysql-bin.000003 | 1069459 |
| mysql-bin.000004 | 501 |
+------------------+-----------+
4 rows in set (0.00 sec)
MariaDB [(none)]> change master to master_host='192.168.8.200',master_user='glq',master_password='123123',master_log_file='mysql-bin.000004',master_log_pos=500;
Query OK, 0 rows affected (0.09 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.8.200Master_User: glqMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000004Read_Master_Log_Pos: 500Relay_Log_File: relay-log.000002Relay_Log_Pos: 529Relay_Master_Log_File: mysql-bin.000004Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 500Relay_Log_Space: 817Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_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: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1
1 row in set (0.00 sec)測試:
MariaDB [(none)]> create database mydata; //創(chuàng)建數據庫;
Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydata |
| mysql |
| performance_schema |
| test |
| testdb |
+--------------------+
6 rows in set (0.00 sec)
MariaDB [(none)]> use mydata;
Database changed
MariaDB [mydata]> show tables;
+------------------+
| Tables_in_mydata |
+------------------+
| test |
+------------------+
1 row in set (0.00 sec)MariaDB [mydata]> desc test;
+--------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------------------+------+-----+---------+----------------+
| id | tinyint(3) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(20) | NO | | NULL | |
| CardID | varchar(20) | YES | | NULL | |
+--------+---------------------+------+-----+---------+----------------+
3 rows in set (0.07 sec)MariaDB [mydata]> insert into test(name,CardID)values('glq',1231223),('zyn',123123321);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0在200 server查看驗證:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydata |
| mysql |
| performance_schema |
| test |
| testdb |
+--------------------+
6 rows in set (0.00 sec)MariaDB [(none)]> use mydata;
Database changed
MariaDB [mydata]> create table test(id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,name varchar(20) not null,CardID varchar(20));
Query OK, 0 rows affected (0.06 sec)MariaDB [mydata]> select * from test;
+----+------+-----------+
| id | name | CardID |
+----+------+-----------+
| 2 | glq | 1231223 |
| 4 | zyn | 123123321 |
+----+------+-----------+
2 rows in set (0.00 sec)
至此主主復制配置完成
轉載于:https://www.cnblogs.com/ligao/p/6387389.html
總結
以上是生活随笔為你收集整理的mysql master or master copy的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PlayerDir
- 下一篇: Linux之grep命令详解