MySQL Master-slave replication

Source: Internet
Author: User

principle:Data synchronization with MySQL binary log files steps: First, configure the main library (master) 1. Modify the main library my.cnf configuration file, add the following configuration[Email protected] ~]# nano-w/etc/my.cnf [mysqld] Log-bin=mysql-bin server-id=1 2. Restart MySQL for the configuration to take effect[Email protected] ~]# service mysqld restart 3. Log in to MySQL as root, create a master-slave replication user and authorize master-slave replication[[email protected] ~]# mysql-uroot-p mysql> CREATE USER ' Repl' @ '% ' identified by ' Repl _password';mysql> GRANT REPLICATION SLAVE on * * to ' Repl' @ '% ';mysql> FLUSH privileges; 4. View the main library binary log coordinates (remember values for file and position columns)mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+| File             | Position | binlog_do_db | binlog_ignore_db |+------------------+----------+--------------+------------------+| Mysql-bin. 000001 747      |              |                  | +------------------+----------+--------------+------------------+

ii. configuration from the library (Slave) 1. Modify the MY.CNF configuration file from the library and add the following configuration[Email protected] ~]# nano-w/etc/my.cnf [mysqld] server-id=2 2. Modify the MySQL server UUID (optional, if you are cloning a virtual machine directly, this step must be done)Mv/var/lib/mysql/auto.cnf/var/lib/mysql/auto.cnf.bak 3. Restart MySQL for the configuration to take effect and generate a new MySQL server UUID[Email protected] ~]# service mysqld restart 4. Log in to MySQL with root and set the binary log file to access the main library from the library[Email protected] ~]# mysql-uroot-p
mysql> Change MASTER        to-, master_host='master_host_name',        -master_user='repl',    --    Master_ password='repl_password',        master_log_file='  mysql-bin.000001',        master_log_pos=747;
5. Start slavemysql> start slave; 6. Check the Slave connection status (slave_io_running, slave_sql_running yes indicates successful connection)Mysql> show slave status \g; 1. Row *************************** slave_io_state:waiting for master to send event master_host:192.168.168.110 Master_Us Er:repl master_port:3306 connect_retry:60 master_log_file:mysql-bin.000001 read_master_log_pos:747 Relay_Log_Fil e:localhost-relay-bin.000002 relay_log_pos:320 relay_master_log_file:mysql-bin.000001 Slave_io_running:yes Slave_S Ql_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.