MySQL master-slave configuration study notes

MySQL master-slave configuration study notes

● I was planning to buy some cloud data to provide some security for my new project. After a round of searching between Alibaba Cloud and Tencent Cloud, I concluded that they are too expensive. Isn't it just that the data is backed up? In that case, I might as well make a backup myself.

● I have two Raspberry Pis at home, so I can just back up MySQL to them. There are tutorials online, so I’ll start right away. I searched several articles on segmentfault mysql and did what they said, but of course it was unsuccessful. If it had been successful, I would not have written this article. ps: Their tutorials are all correct.

● Now we start configuring the master and slave servers, just like the online tutorials, because that’s what I followed.

1. Master settings (master)

Modify the mysql configuration file, usually in /etc/mysql/my.conf

server-id=1 //Set mysql's ID identifierlog-bin=/var/lib/mysql/mysql-bin //log-bin log file, master-slave backup is implemented using this log record#binlog-do-db=mysql1 #Name of the database to be backed up. If you back up multiple databases, just set this option repeatedly#binlog-ignore-db=mysql2 #Name of the database that does not need to be backed up. If you back up multiple databases, just set this option repeatedly#log-slave-updates=1 #This parameter must be added when the slave library is also the master library of other slave libraries, otherwise the updated records will not be written to the binary file in binglog#slave-skip-errors=1 #Skip errors and continue the replication operation (optional)

Add 2 accounts for synchronization in the main mysql

mysql>grant replication slave on *.* to 'sync-1'@'%' identified by '123456';

mysql>grant replication slave on *.* to 'sync-2'@'%' identified by '123456';

Restart msql

mysql>show master status; //You can view the status of the master mysql

2. Slave settings

Modify the MySQL configuration file my.conf. The configuration methods of the two slave nodes are the same.

server-id=2
#log-bin=/var/lib/mysql/mysql-bi //No need to set log file from mysql

Add command parameters in mysql, master_log_file and master_log_pos can be queried in master mysql using show master status

mysql>change master to master_host='192.168.145.222',master_user='sync-1',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=308; 

mysql>start slave //Startmysql>show slave status\G //Query status, if both Slave_IO_Running and Slave_IO_Running are yes, it means success

3. Problems encountered during setup

Last_Errno: 1146

When I set up the slave, my master MySQL already had a table. There was no record in the binlog binary log when the table was created, so the slave MySQL could not write data. At this time, I had to manually import the database file into the slave MySQL. The reason was that the online tutorials all showed newly installed master MySQL and slave MySQL, so there was no problem of existing data.

Last_Errno: 1062

Error 'Duplicate entry 'xxxxx' for key 'PRIMARY'' on query

Primary key conflict. This problem is more complicated. It should be that the table settings are incorrect. I later found a solution to this problem on Stack Overflow.

# on slave
mysql> stop slave;
mysql> flush privileges;
# on master rest master
mysql> reset master;
# on slave;
mysql> reset slave;
mysql> start slave;

This is the end of this article about the study notes on MySQL master-slave configuration. For more detailed information on MySQL master-slave configuration, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Record the whole process of MySQL master-slave configuration based on Linux
  • MySQL5.7 master-slave configuration example analysis
  • Docker mysql master-slave configuration details and examples
  • A brief note on the MySQL master-slave configuration solution
  • Sharing of the master-slave configuration method of MySQL database
  • Mysql implements master-slave configuration and multi-master-multi-slave configuration

<<:  Vue's vue.$set() method source code case detailed explanation

>>:  JavaScript implements changing the color of a web page through a slider

Recommend

How to configure https for nginx in docker

Websites without https support will gradually be ...

Vue+echart realizes double column chart

This article shares the specific code of vue+echa...

Docker dynamically exposes ports to containers

View the IP address of the Container docker inspe...

Native JS to achieve special effects message box

This article shares with you a special effect mes...

Detailed analysis of the difference between Ref and Reactive in Vue3.0

Table of contents Ref and Reactive Ref Reactive T...

A brief introduction to the usage of decimal type in MySQL

The floating-point types supported in MySQL are F...

How to set password for mysql version 5.6 on mac

MySQL can be set when it is installed, but it see...

Implementation of postcss-pxtorem mobile adaptation

Execute the command to install the plugin postcss...

Example code for drawing double arrows in CSS common styles

1. Multiple calls to single arrow Once a single a...

How to implement the Vue mouse wheel scrolling switching routing effect

A root routing component (the root routing compon...

JavaScript implements the detailed process of stack structure

Table of contents 1. Understanding the stack stru...

How to make form input and other text boxes read-only and non-editable in HTML

Sometimes, we want the text boxes in the form to b...

Comparison of mydumper and mysqldump in mysql

If you only want to back up a few tables or a sin...

Analysis of three parameters of MySQL replication problem

Table of contents 01 sql_slave_skip_counter param...

Summary of common commands in Dockerfile

Syntax composition: 1 Annotation information 2 Co...