最快的从库搭建方法
0,准备从库第一次数据备份,临时锁所有表
开启窗口1
- mysql> flush tables with read lock;
- Query OK, 0 rows affected (0.00 sec)
- mysql> show master status;
- +------------------+----------+--------------+------------------+
- | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
- +------------------+----------+--------------+------------------+
- | mysql-bin.000003 | 194554 | | |
- +------------------+----------+--------------+------------------+
- 1 row in set (0.00 sec)
- PS:这个窗口不能exit,要一直保持知道tar完包为止。
-- 重新开一个shell窗口,去数据文件目录tar包
开启窗口2
[root@myfstv_21_11 data]# tar -zcvf mysqla1.tar.gz mysqla
tar -zcvf mysqla1.tar.gz mysqla 压缩完毕
切换到窗口1,执行解锁命令
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
mysql>
进入21.12,传输tar包
[root@myfstv_21_12 data]# scp xx.xx0.xx.11:/data/mysqla1.tar.gz ./
1,在/usr/local/mysqla/my.cnf里面添加
log-bin=/log/mysqla/mysql-bin
long_query_time = 1
slow_query_log
log_slow_queries=/log/mysqla/slow.log
max_binlog_size=1024M
binlog_cache_size=4M
max_binlog_cache_size=512M
binlog_format=mixed
log_slave_updates = 1
read_only=1
relay-log=relay-bin
relay-log-index=relay-bin
2,在xx.12上面mysqla上面执行
mysql>change
master to master_user='repl', master_password='mb',
master_host='xx.xx0.xx.11',
master_log_file='mysql-bin.000003',master_log_pos=194554;
mysql>start slave;
mysql> show slave status\G;