MySQL master-slave configuration (master slave)

Source: Internet
Author: User
Tags mysql in mysql query unique id

MySQL Master-slave replication
(Super Simple)

How to install MySQL database, do not say here, just say its master-slave copy, the steps are as follows:

1, the master-slave server for the following actions
1.1. Consistent version
1.2. Initialize the table and start MySQL in the background
1.3, change the root password

2. Modify master server Master:
#vi/etc/my.cnf
[Mysqld]
Log-bin=mysql-bin//[must] enable binary logging
server-id=222//[must be] server unique ID, default is 1, usually take IP last paragraph

3. Modify the slave from the server:
#vi/etc/my.cnf
[Mysqld]
Log-bin=mysql-bin//[not required] enable binary logging
server-id=226//[must be] server unique ID, default is 1, usually take IP last paragraph

4. Restart MySQL for two servers
/etc/init.d/mysql restart

5. Establish an account on the primary server and authorize slave:
#/usr/local/mysql/bin/mysql-uroot-pmttang
Mysql>grant REPLICATION SLAVE on * * to ' mysync ' @ ' percent ' identified by ' q123456 '; Generally do not use the root account,“%” means that all clients may even, as long as the account, the password is correct, here can be specific client IP instead, such as 192.168.145.226, enhance security.

6, log on to the master server MySQL, query the status of Master
Mysql>show Master status;
+------------------+----------+--------------+------------------+
| 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 again after performing this step to prevent the change of the primary server state value

7. Configure the slave from the server:
Mysql>change Master to master_host= ' 192.168.145.222 ', master_user= ' Mysync ', master_password= ' q123456 ',
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; To start the Copy from Server feature

8. Check the status of the replication function from the server:

Mysql> Show Slave Status\g

1. Row ***************************

Slave_io_state:waiting for Master to send event
master_host:192.168.2.222//Primary server address
Master_user:mysync//Authorization account name, try to avoid using root
master_port:3306//Database port, some versions do not have this line
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
Slave_sql_running:yes//This status must be Yes
......

Note: The slave_io and slave_sql processes must function normally, that is, the Yes state, otherwise it is an error state (e.g., one of the No is an error).

The above operation process, the master and slave server configuration is complete.

9, the master-slave server test:

master server MySQL, build the database, and create a table in this library to insert a piece of data:

mysql> CREATE DATABASE hi_db;
Query OK, 1 row Affected (0.00 sec)

mysql> use hi_db;
Database changed

Mysql> CREATE TABLE HI_TB (ID int (3), name char (10));
Query OK, 0 rows Affected (0.00 sec)

mysql> INSERT INTO HI_TB values (001, ' Bobu ');
Query OK, 1 row Affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| Information_schema |
| hi_db |
| MySQL |
| Test |
+--------------------+
4 rows in Set (0.00 sec)

MySQL Query from server:

mysql> show databases;

+--------------------+
| Database |
+--------------------+
| Information_schema |
|       hi_db | I ' M here, you see?
| MySQL |
| Test |

+--------------------+
4 rows in Set (0.00 sec)

Mysql> Use hi_db
Database changed
Mysql> select * from HI_TB; View new specific data on the primary server
+------+------+
| ID | name |
+------+------+
| 1 | Bobu |
+------+------+
1 row in Set (0.00 sec)

10. Completion:
Write a shell script that monitors Slave's two yes (Slave_io and slave_sql processes) with Nagios, and if only one or 0 Yes is found, it indicates that there is a problem with the master-slave, send SMS alerts.

This article is from the "System network operation and Maintenance" blog, please be sure to keep this source http://369369.blog.51cto.com/319630/790921

MySQL master-slave configuration (master slave)

Related Article

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.