search
HomeDatabaseMysql TutorialDetailed explanation of the example code of MySQL5.7 master-slave configuration

This article mainly provides a detailed analysis of MySQL5.7 master-slave configuration examples, which has certain reference value. Interested friends can refer to

MySQL5.7 Master-slave configuration implementation method, the specific content is as follows

Installation environment:

Master: 10.211.55.11, Redhat6.5, MySQL5.7.12
Slave : 10.211.55.12, Redhat6.5, MySQL5.7.12

Master’s my.cnf configuration:

Slave’s my.cnf configuration:

You can specify which databases need to be copied and which ones do not need to be copied. For example, if you comment out the contents in my my.cnf configuration, I will copy them all by default. . After modifying the my.cnf configuration file, both machines restart the MySQL service: service mysqld restart. The next operation is more important:
Mysql configuration of the Master machine

1. mysql -u root -p login;
2. Execute the following command, which means that the root copy permission and File permission of 10.211.55.12 will be granted. Of course, you can also create another user to operate, not necessarily root. , 123456 represents the password.

GRANT FILE ON *.* TO 'root'@'10.211.55.12' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO 'root'@'10.211.55.12' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;

3. Execute the show master status command, as shown in the figure:

Detailed explanation of the example code of MySQL5.7 master-slave configuration

##MySQL configuration of the Slave machine

1. mysql -u root -p login;

2. Execute the following instructions in sequence:

mysql> stop slave;
mysql> change master to master_host='10.211.55.11',master_user='root',master_password='123456',master_log_file='mysql-bin.000003', master_log_pos=154;
mysql> start slave;

Note:
The values ​​in master_log_file and master_log_pos should correspond to the values ​​in the show master status result of the Master machine (as shown above).

3. Check the slave

status, show slave status\G; Note that the "\G" here is to display the formatting result. If there are no errors, the slave status The results are as shown in the figure:

## Test:


Create a database in Master:

mysql> create database test;
mysql> create table t1 (id int,name varchar(200),createtime timestamp,key(id));
mysql> insert into t1 values (1,'aa',now());
mysql> insert into t1 values (3,'bb',now());

After performing the above operations, switch to the Salve machine to see if it is synchronized. If nothing else, it should be synchronized immediately.

My machine displays as follows:



The above is the detailed content of Detailed explanation of the example code of MySQL5.7 master-slave configuration. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools