MySQL主从复制

一.前言

本文未完成,不适阅读!!!

主从复制
ntpdate 172.18.0.1
yum install -y mariadb-server

vim /etc/my.cnf
skip_name_resolve = ON
innodb_file_per_table = ON
server_id=1
log-bin=master-log

systemctl start mariadb
MariaDB [(none)]> show global variables like ‘log_bin’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| log_bin | ON |
+—————+——-+
MariaDB [(none)]>GRANT REPLICATION CLIENT,REPLICATION SLAVE ON . TO ‘zhaoyang’@’172.18.46.%’ IDENTIFIED BY ‘123123’;
MariaDB [(none)]>FLUSH PRIVILEGES;
MariaDB [(none)]> show master status;
+——————-+———-+————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————-+———-+————–+——————+
| master-log.000003 | 1873 | | |
+——————-+———-+————–+——————+

vim /etc/my.cnf
skip_name_resolve = ON
innodb_file_per_table = ON
server_id=2
relay_log=relay-log
read_only=ON
systemctl start mariadb
MariaDB [(none)]> show global variables like ‘relay_log’;
+—————+———–+
| Variable_name | Value |
+—————+———–+
| relay_log | relay-log |
+—————+———–+

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST=’172.18.46.5’,MASTER_USER=’zhaoyang’,MASTER_PASSWORD=’123123’,MASTER_LOG_FILE=’master-log.000003’,MASTER_LOG_POS=1873;
MariaDB [(none)]>SHOW SLAVE STATUS;
Slave_IO_Running: No
Slave_SQL_Running: No
Seconds_Behind_Master: NULL
MariaDB [(none)]>START SLAVE IO_THREAD,SQL_THREAD;
MariaDB [(none)]>SHOW SLAVE STATUS;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0
MariaDB [(none)]> CREATE DATABASE CHECK1;
MariaDB [(none)]> SHOW DATABASES;
+——————–+
| Database |
+——————–+
| information_schema |
| CHECK1 |
| mysql |
| performance_schema |
| test |
+——————–+

双主复制
vim /etc/my.cnf
skip_name_resolve = ON
innodb_file_per_table = ON
server_id=2
relay_log=relay-log
log-bin=master-log
auto_increment_offset=2
auto_increment_increment=2

MariaDB [(none)]>GRANT REPLICATION CLIENT,REPLICATION SLAVE ON . TO ‘zhaoyang’@’172.18.46.%’ IDENTIFIED BY ‘123123’;
MariaDB [(none)]> FLUSH PRIVILEGES;

MariaDB [(none)]>SHOW MASTER STATUS;
+——————-+———-+————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————-+———-+————–+——————+
| master-log.000001 | 424 | | |
+——————-+———-+————–+——————+

vim /etc/my.cnf
skip_name_resolve = ON
innodb_file_per_table = ON
server_id=1
log-bin=master-log
relay_log=relay-log
auto_increment_offset=1
auto_increment_increment=2

MariaDB [(none)]>CHANGE MASTER TO MASTER_HOST=’172.18.46.4’,MASTER_USER=’zhaoyang’,MASTER_PASSWORD=’123123’,MASTER_LOG_FILE=’master-log.000001’,MASTER_LOG_POS=424;
MariaDB [(none)]> START SLAVE IO_THREAD,SQL_THREAD;
MariaDB [(none)]> SHOW SLAVE STATUS\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0

你可能感兴趣的:(linux,maria,db)