MySQL Master-slave replication

Source: Internet
Author: User

# #主库
#开启节点
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.