MySQL Master-slave replication

Source: Internet
Author: User

Determine two servers MySQL version consistent 1. Modify master server Master configuration # Edit Profile vi/etc/my.cnf [mysqld] Log-bin=mysql-bin//[must] enable binary log, add log directory Server-id=7// [must] from the server unique ID, the default is 1, generally take the IP last paragraph 2. Modify from server slave config # edit profile vi/etc/my.cnf [mysqld] Log-bin=mysql-bin//[must] enable binary log, add log directory Server-id=5//[must be] The primary server unique ID, the default is 1, generally take the IP last paragraph 3. Restart the MySQL service mysqld restart4. Establish an account on the primary server and authorize Slave:/usr/local/mysql/bin /mysql-u root-p #设置访问权限grant Replication Slave on * * to ' repl ' @ ' 10.162.100.5 ' identified by ' repl '; Flush privileges;//generally do not use the root account, "%" means that all clients may be connected, as long as the account, the password is correct, the specific client IP can be replaced here, such as 192.168.145.226, enhance security.   5. Log in to the master server for MySQL, and query the master status Mysql>show master State; +------------------+----------+--------------+------------------+   | File | Position | binlog_do_db |   binlog_ignore_db | +------------------+----------+--------------+------------------+   |      mysql-bin.000004 |              308 |                  |   | +------------------+----------+--------------+------------------+ 1 row in Set (0.00 sec) Note: Do not operate the master server MySQL after performing this step to prevent the primary Server-likeState value change 6. Configure from server Slave:mysql>change master to master_host= ' 10.162.100.5 ', master_user= ' repl ', master_password= ' repl ',   Master_log_file= ' mysql-bin.000004 ', master_log_pos=308;   Be careful not to disconnect, there are no single quotes around 308 digits.    Mysql>start slave; Start replication from server 7. Check replication from server status: Mysql> show slave status\g *************************** 1. Row *************************** slave_io_state:waiting for master to send event master_host:19 2.168.2.222//Primary server address Master_user:mysync//Authorization account name, try to avoid using root master_port:3306//database port, partial version     No trip connect_retry:60 master_log_file:mysql-bin.000004 read_master_log_pos:600 #同步读取二进制日志的位置, greater than or equal to Exec_master_log_pos relay_log_file:ddte-relay-bin.000003 Relay_log_pos: 251 relay_master_log_file:mysql-bin.000004 Slave_io_running:yes//This status must be Yes Sla Ve_sql_running:yes//This status must be Yes ... Note: Slave_io and SlavThe E_SQL process must run normally, that is, the Yes state, otherwise it is a state of error (for example, one of the No is an error). 8. Finish: Write a shell script, use Nagios to monitor the Slave two yes (Slave_io and slave_sql process), if only one or 0 yes, it indicates the master-slave problem, send SMS alert.

  

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.