Browse Source

mariadb replica without downtime and without locking

master
Markus Bergholz 2 years ago
parent
commit
78862cc4dd
  1. 49
      til.md

49
til.md

@ -569,39 +569,54 @@ grow / resize btrfs partition
`sudo btrfs filesystem resize +3g /mnt/backup`
# MariaDB replica
# MariaDB replica without locking (innodb) and without downtime
use rsync - everything else sucks!
if you can't use rsync, you must lock all tables and use mysqldump.
1. create replication user
```sql
GRANT SELECT,REPLICATION USER,REPLICATION CLIENT ON *.*
TO repl@'%' IDENTIFIED BY 'repl';
```
# on mariadb writer instance
rsync -Sa --progress --delete /var/lib/mysql/ root@target_replica_host:/var/lib/mysql/
mysql> flush tables with read lock;
mysql> show master status;
2. dump master
rsync -Sa --progress --delete /var/lib/mysql/ root@target_replica_host:/var/lib/mysql/
```
mysqldump --master-data=1 --single-transaction --flush-privileges \
--routines --triggers --all-databases > writer_dump.sql
```
3. grep for bin log position
mysql> unlock tables;
mysql> CREATE USER 'repl'@'%' IDENTIFIED BY 'repl';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
```
grep "CHANGE MASTER TO MASTER_LOG_FILE" MySQLData.sql |head -n 1
CHANGE MASTER TO MASTER_LOG_FILE='defadda3c269-bin.000001', MASTER_LOG_POS=516401;
```
# on new mariadb reader replica
# start with server_id != 1
4. apply dump on reader node
CHANGE MASTER TO
```
mysql < writer_dump.sql`
```
5. set replication status on reader node
```sql
CHANGE MASTER TO
MASTER_HOST='mariadb_writer_host',
MASTER_USER='repl',
MASTER_PASSWORD='repl',
MASTER_PORT=3306,
MASTER_LOG_FILE='83e8e184d773-bin.000001',
MASTER_LOG_POS=335,
MASTER_LOG_FILE='defadda3c269-bin.000001',
MASTER_LOG_POS=516401,
MASTER_CONNECT_RETRY=10;
// MASTER_USE_GTID = slave_pos # for GTID
```
start slave;
6. start slave
```
START SLAVE;
SHOW SLAVE STATUS;
```
# pip

Loading…
Cancel
Save