Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of MySQL Master-Slave configuration

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the MySQL master-slave configuration example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.

1. Primary node authorizes synchronous users

The official documentation is carried out in two steps:

Mysql > CREATE USER 'repl'@'%.mydomain.com' IDENTIFIED BY' slavepass'

Mysql > GRANT REPLICATION SLAVE ON. TO'repl'@'%.mydomain.com'

In fact, a single command is enough:

Grant replication slave,reload,super on *. * to 'repl'@'192.168.56.103' identified by' asdfjkl'

two。 Master node modifies configuration file

Vi / data/mysqldata/3306/my.cnf

In fact, the content is mainly server-id=102. For InnoDB, it is recommended to add two parameters:

[mysqld]

Server-id=102

# binlog-ignore-db = mysql

# replicate-do-db = xxdb

# InnoDB

Innodb_flush_log_at_trx_commit=1

Sync_binlog=1

Restart MySQL on the primary node:

Shell > mysqladmin shutdown

Shell > mysqld_safe-- defaults-file=/data/mysqldata/3306/my.cnf &

3. Modify the configuration file from the node

Vi / data/mysqldata/3306/my.cnf

Add:

[mysqld]

Server-id=103

# replicate-do-db = xxdb

Restart MySQL from the node:

Shell > mysqladmin shutdown

Shell > mysqld_safe-- defaults-file=/data/mysqldata/3306/my.cnf &

4. Check the status after the master node is locked

The primary node is locked:

Mysql > FLUSH TABLES WITH READ LOCK

Master node view status:

(root@localhost) [(none)] > show master status

->

+-+

| | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | |

+-+

| | mysql-bin.000011 | 432 |

+-+

1 row in set (0.00 sec)

5. Configure and start synchronization and view status from the node

From the node configuration:

Mysql > CHANGE MASTER TO

MASTER_HOST='192.168.56.102'

MASTER_USER='repl'

MASTER_PASSWORD='asdfjkl'

MASTER_LOG_FILE='mysql-bin.000011'

MASTER_LOG_POS=432

The log file and current location here are filled in based on the status of the primary node found in the previous step.

Start SLAVE:

Mysql > START SLAVE

View the status of the slave node:

Mysql > show slave status\ G

6. Unlock the master node and verify that the slave node is synchronized properly

Unlock the primary node:

Mysql > UNLOCK TABLES

Build the database on the master node:

Mysql > create database xxdb

From the node to see if it is synchronized:

Mysql > show databases

Thank you for reading this article carefully. I hope the article "sample Analysis of MySQL Master-Slave configuration" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report