Article mind map Why use master-slave replication and read-write separation?
The principle of master-slave replication
How to implement master-slave replication** Environment display, I use two virtual machines for demonstration, IP is Master (135) and 136 (Slave) For a more intuitive look, the following figure shows the effects of the three machines (data changes: such as inster, update, delete...) Master Configuration**Use the command line to enter mysql: > mysql -uroot -p //Enter password> //192.168.190.136 is the IP address of the slave machine > GRANT REPLICATION SLAVE ON *.* to 'root'@'192.168.190.136' identified by 'rootroot'; //Refresh the system permission table. If not, restart the system to make it effective. > flush privileges; The user configured above is needed when configuring the slave machine. Next, add the configuration to the mysql configuration file /etc/my.cnf: vim /etc/my.cnf //Add #database ID number under [mysqld]. When it is 1, it means master. The master_id of the master and slave cannot be consistent. server-id=1 # Enable binlog log-bin=mysql-bin #The database that needs to be synchronized. If not configured, all databases will be synchronized binlog-do-db=test #The number of days that binlog logs are retained. Logs older than 10 days will be cleared. #To prevent too many files from being too large, resulting in insufficient disk space. expire-logs-days=10 After the configuration is complete, restart mysql
Then enter mysql, check the current binlog log information and record it.
Slave ConfigurationThe Slave configuration is simpler. The slave machine can add server-id in /etc/my.cnf. # Do not repeat with other MySQL service IDs server-id=111 Then log in to the mysql command line. Enter the following sql CHANGE MASTER TO MASTER_HOST='192.168.190.135', //Host IP MASTER_USER='root', // previously created user account MASTER_PASSWORD='rootroot', // previously created user password MASTER_LOG_FILE='mysql-bin.000002', // master host binlog log name MASTER_LOG_POS=245, // binlog log offset Position master_port=3306;//Port After successful operation, start the slave service start slave; Then verify whether the startup is successful. show slave status\G You can see the following information: (The output is long, only part of it is intercepted) Next we can test the master-slave replication Execute SQL on the master host: CREATE TABLE `goods_brand` ( `id` BIGINT (20) UNSIGNED NOT NULL auto_increment, `brand_name` VARCHAR (50) NOT NULL COMMENT 'Brand name', `gmt_create` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `gmt_update` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`id`) ) ENGINE = INNODB DEFAULT CHARSET = utf8 COMMENT = 'Brand table'; After the execution is completed, let's refresh the library table and see You can see that I am executing on the Master machine, and the slave will synchronize directly to it. At this point, the master-slave synchronization of mysql has been completed. Regarding read-write separation, available solutions and monitoring will be written in the next chapter, and the link will be supplemented.
SummarizeThis is the end of this article about MySQL master-slave replication and read-write separation with pictures and text. For more relevant MySQL master-slave replication and read-write separation content, 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:
|
<<: How to implement the King of Glory matching personnel loading page with CSS3
>>: Uncommon but useful tags in Xhtml
There is an interview question that requires: a th...
A simple license plate input component (vue) for ...
In a recent problem, there is such a phenomenon: ...
How to write configuration files and use MyBatis ...
When using a cloud server, we sometimes connect t...
I have previously written an article about recurs...
introduction During the front-end project develop...
Table of contents 1. Basic environment configurat...
The main part of the page: <body> <ul id...
Transactions in MySQL are automatically committed...
Table of contents 1. Introduction 2. es5 method 3...
MySQL password is correct but cannot log in local...
This article mainly introduces an example of how ...
<br /> When we browse certain websites and s...
Linux col command The Linux col command is used t...