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

The creation method of mysql Master and Slave

2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly introduces "the creation method of mysql master and slave". In the daily operation, I believe that many people have doubts about the creation method of mysql master and slave. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the creation method of mysql master and slave". Next, please follow the editor to study!

Environment introduction: master library 172.17.10.19 slave library 172.17.10.21

1. Create / etc/my.cnf the main library, and modify the key value in [mysqld] to increase it.

Server-id=1

Log-bin=myfk_bin_log

2. Add users to the main library to read the main library log from the library.

Grant replication slave,reload,super on *. * to 'slave'@'172.17.10.21' identified by' fookoo_MS'

3. Connect the slave library to the master library for testing.

/ opt/mysql/bin/mysql-u slave-p-h 172.17.10.19

4. Stop the slave library, modify the slave library / etc/my.cnf, and add options:

[mysqld]

Server-id=2

Master-host=172.17.10.19

Master-user=slave

Master-password=fookoo_MS

5. Start the slave library to synchronize the data of the master and slave libraries.

/ opt/mysql/share/mysql/mysql start

/ opt/mysql/bin/mysql-u root-p

Mysql > load data from master

Explanation: this step can also be tested by pouring in or directly in the directory.

6. Conduct tests:

Create tables in the main library

Mysql > create database sampdb

Mysql > create table new (name char (20), phone char (20))

Mysql > insert into new ('abc,'0532555555')

Open the slave library and see:

/ opt/mysql/bin/mysql-u root-p

Mysql > show database

Mysql

Sampdb

Test

Mysql > use sampdb

Mysql > show tables

New

Indicates that the master-slave database was created successfully.

7. Master-slave database related commands:

Slave stop; slave start

Start to stop from the database.

Show slave statusG

Displays which master database binary log is being read from the slave library

Purge master logs to 'binlog.000004'

This command is very careful to delete the useless binary log files of the primary database. If deleted by mistake, there is no way to update automatically from the library.

Change master

Modify the parameters from above to use.

Change master to master_host='172.17.10.19', master_user='slave', master_password='fookoo'

Master_log_file='myfk_bin_log.000007', master_log_pos=210

At this point, the study of "the creation method of mysql master and slave" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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