# #主库
#开启节点
Echo-e "Log-bin=mysql-bin\nserver-id=1" >>/etc/my.cnf
#开启数据库
/etc/init.d/mysqld restart
#添加从库用户
Grant Replication Slave on * * to ' rep ' @ ' 172.16.1.% ' identified by ' 123456 ';
Flush privileges;
#锁库
Flush table with read lock;
Show master status;
Show variables like "%timeout%"; View the time-out of a lock interactive and wait
#备份
Mysqldump-uroot-a-B--events|gzip>/opt/rep.sql.gz
#开锁
Unlock tables;
= = from Library = =
Small pits: Because MySQL in the Yum repository is a clone, this command is added
Mv/application/mysql/data/auto.cnf{,.bak}
Just like the clone virtual machine effect.
#增加节点
Echo-e "log-bin=mysql-bin\nserver-id=2" >>/etc/my.cnf
/etc/init.d/mysqld restart
#导入数据
The SCP from the main library to the library, and the data
SCP rep.sql.gz [Email protected]:/opt
Zcat rep.sql.gz |mysql-uroot-p123456
#在主库输入show Master status; View Master_log_file and Master_log_pos
Mysql> Show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | binlog_do_db | binlog_ignore_db | Executed_gtid_set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 405 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in Set (0.00 sec)
#从库输入
: Change MASTER to
Master_host= ' 172.16.1.51 ',
master_port=3306,
Master_user= ' rep ',
Master_password= ' 123456 ',
Master_log_file= ' mysql-bin.000001 ',
master_log_pos=405;
#开启从库
Start slave;
#查看状态
Show Slave Status\g
There are two yes.
Slave_io_running:yes
Slave_sql_running:yes
MySQL Master-slave replication