MySQL Replication configuration

Source: Internet
Author: User

MySQL Replication configuration
1, modify the host (Master) configuration file (MY.CNF)
server_id = 1
Log_bin = Mysql-bin

2. Modify the Slave (slave) configuration file
#主备环境下需要唯一
server_id = 2

3. The host creates replication distribution users and authorizes replication distribution
CREATE USER ' repl ' @ '%.mydomain.com ' identified by ' slavepass ';
GRANT REPLICATION SLAVE on * * to ' repl ';

4. Reboot the host to make the configuration effective

5. Get the host replication distribution point
FLUSH TABLES with READ LOCK;
SHOW MASTER STATUS;
UNLOCK TABLES;
Get a result similar to the following
+------------------+----------+--------------+------------------+
| File | Position | binlog_do_db | binlog_ignore_db |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 73 | Test | Manual,mysql |
+------------------+----------+--------------+------------------+
Where the File/position field needs to be used from the machine


6. Restart the slave machine

7. Setting the host information from the slave
The statement resembles the following
Change MASTER to master_host= ' master_host_name ', master_user= ' replication_user_name ', master_password= ' Replication_ Password ', master_log_file= ' recorded_log_file_name ', master_log_pos=recorded_log_position;
which
Master_log_file= ' Recorded_log_file_name ' in Recorded_log_file_name as the FILE field content in Show Master status
Master_log_pos=recorded_log_position in recorded_log_position as Position field content in Show Master status

SHOW SLAVE status gets something like the following
+----------------------------------+-----------------+-------------+-------------+---------------+------------- -----+---------------------+----------------------------+---------------+-----------------------+-------------- ----+-------------------+-----------------+---------------------+--------------------+------------------------+ -------------------------+-----------------------------+------------+------------+--------------+-------------- -------+-----------------+-----------------+----------------+---------------+--------------------+------------- -------+--------------------+-----------------+-------------------+----------------+-----------------------+--- ----------------------------+---------------+---------------+----------------+----------------+---------------- -------------+------------------+--------------------------------------+--------------------------------------- -----------------+-----------+---------------------+----------------------------------------------------------- ------------------+--------------------+-------------+-------------------------+--------------------------+----- -----------+--------------------+--------------------+-------------------+---------------+
| Slave_io_state | Master_host | Master_user | Master_port | Connect_retry | Master_log_file | Read_master_log_pos | Relay_log_file | Relay_log_pos | Relay_master_log_file | slave_io_running | slave_sql_running | replicate_do_db | replicate_ignore_db | replicate_do_table | replicate_ignore_table | replicate_wild_do_table | replicate_wild_ignore_table | Last_errno | Last_error | Skip_counter | Exec_master_log_pos | Relay_log_space | until_condition | Until_log_file | Until_log_pos | master_ssl_allowed | Master_ssl_ca_file | Master_ssl_ca_path | Master_ssl_cert | Master_ssl_cipher | Master_ssl_key | Seconds_behind_master | Master_ssl_verify_server_cert | Last_io_errno | Last_io_error | Last_sql_errno | Last_sql_error | Replicate_ignore_server_ids | master_server_id | Master_uuid | Master_info_file | Sql_delay | Sql_remaining_delay | Slave_sql_running_state | Master_retry_count | Master_bind | Last_io_error_timestamp | Last_sql_error_timestamp | MASTER_SSL_CRL | Master_ssl_crlpath | RetriEved_gtid_set | Executed_gtid_set | auto_position |
+----------------------------------+-----------------+-------------+-------------+---------------+------------- -----+---------------------+----------------------------+---------------+-----------------------+-------------- ----+-------------------+-----------------+---------------------+--------------------+------------------------+ -------------------------+-----------------------------+------------+------------+--------------+-------------- -------+-----------------+-----------------+----------------+---------------+--------------------+------------- -------+--------------------+-----------------+-------------------+----------------+-----------------------+--- ----------------------------+---------------+---------------+----------------+----------------+---------------- -------------+------------------+--------------------------------------+--------------------------------------- -----------------+-----------+---------------------+----------------------------------------------------------- ------------------+--------------------+-------------+-------------------------+--------------------------+----- -----------+--------------------+--------------------+-------------------+---------------+
| Waiting for Master to send event | 192.168.153.128 | Repl | 3306 | 60 | mysql-bin.000019 | 800 | localhost-relay-bin.000003 | 676 | mysql-bin.000019 | Yes | Yes | | | | | | | 0 | | 0 | 800 | 853 | None | | 0 | No | | | | | | 0 | No | 0 | | 0 | | | 1 | aaf47eb1-fa78-11e3-a424-000c2932455f | /home/jiangyx/mysql/replication/slave/data/master.info | 0 | NULL | Slave have read all relay log; Waiting for the slave I/O thread to update it | 86400 | | | | | | | | 0 |
+----------------------------------+-----------------+-------------+-------------+---------------+------------- -----+---------------------+----------------------------+---------------+-----------------------+-------------- ----+-------------------+-----------------+---------------------+--------------------+------------------------+ -------------------------+-----------------------------+------------+------------+--------------+-------------- -------+-----------------+-----------------+----------------+---------------+--------------------+------------- -------+--------------------+-----------------+-------------------+----------------+-----------------------+--- ----------------------------+---------------+---------------+----------------+----------------+---------------- -------------+------------------+--------------------------------------+--------------------------------------- -----------------+-----------+---------------------+----------------------------------------------------------- ------------------+--------------------+-------------+-------------------------+--------------------------+----- -----------+--------------------+--------------------+-------------------+---------------+
Where the slave_io_running/slave_sql_running are all successful for Yes

Attention:
1, if the slave is by copying the entire MySQL data, then you need to modify the data directory Auto.cnf file uuid, to ensure that the host and standby the UUID is not the same. Otherwise there will be an error message in show slave status "Fatal error:the slave I/O thread stops because master and slave have equal MySQL server UUIDs; These uuids must is different for replication to work. ”

Reference:
1, http://dev.mysql.com/doc/refman/5.6/en/replication-howto.html

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.