background:Since the company's projects seem to be unable to withstand the pressure of concurrency recently, optimization is imminent. Since the current system is a single database system, we have tried our best to optimize where possible, but the database bottleneck still severely limits the project's concurrent capabilities. So we considered adding a database to increase the project's concurrency capabilities. Ideas:1: Create a centralized library: mainly to store historical data. Use as a query. 2: Create multiple business libraries: to meet the high concurrency capabilities of the project. Demo environment:1: VM ware virtual machine - centOS 7
2: MySQL 5.7 step1: Main library 100 Set up my.cnf. [mysqld] lower_case_table_names = 1 # Table names are case insensitive server-id = 100 log_bin = mysql-bin #Start binlog recording binlog_format = MIXED #Every time a transaction is committed, MySQL will flush the binlog. This is the safest setting but it has the greatest performance loss. #In this case, the system may lose the data of one transaction only if the host operating system where the database is located is damaged or the power is suddenly lost. #However, although binlog is sequential IO, if sync_binlog=1 is set, multiple transactions are submitted at the same time. #It also greatly affects MySQL and IO performance. Set as needed. sync_binlog = 1 # Number of days after which binary logs are automatically deleted/expired. The default value is 0, which means no automatic deletion. expire_logs_days = 7 #binlog_cache_size = 128m #max_binlog_cache_size = 512m #max_binlog_size = 256M # Need to synchronize the database binlog-do-db = dev # No synchronization library is required binlog-ignore-db = mysql binlog_ignore_db = information_schema binlog_ignore_db = performance_schema binlog_ignore_db = sys datadir=/var/lib/mysql Set up slave users #mysql -uroot -p # password: xxxxxx # mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY 'root1234'; # mysql> flush privileges; # quit; # systemctl restart mysqld; # show master status \G #*************************** 1. row *************************** File:mysql-bin.000001 Position: 886 Binlog_Do_DB: dev Binlog_Ignore_DB: mysql,information_schema,performance_schema,sys Executed_Gtid_Set: 1 row in set (0.00 sec) 2: Main library 200 Set up my.cnf. [mysqld] lower_case_table_names = 1 # Table names are case insensitive server-id = 200 log_bin = mysql-bin #Start binlog recording binlog_format = MIXED #Every time a transaction is committed, MySQL will flush the binlog. This is the safest setting but it has the greatest performance loss. #In this case, the system may lose the data of one transaction only if the host operating system where the database is located is damaged or the power is suddenly lost. #However, although binlog is sequential IO, if sync_binlog=1 is set, multiple transactions are submitted at the same time. #It also greatly affects MySQL and IO performance. Set as needed. sync_binlog = 1 # Number of days after which binary logs are automatically deleted/expired. The default value is 0, which means no automatic deletion. expire_logs_days = 7 #binlog_cache_size = 128m #max_binlog_cache_size = 512m #max_binlog_size = 256M # Need to synchronize the database binlog-do-db = dev # No synchronization library is required binlog-ignore-db = mysql binlog_ignore_db = information_schema binlog_ignore_db = performance_schema binlog_ignore_db = sys datadir=/var/lib/mysql Set up slave users #mysql -uroot -p # password: xxxxxx # mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY 'root1234'; # mysql> flush privileges; # quit; # systemctl restart mysqld; # show master status \G #*************************** 1. row *************************** File:mysql-bin.000001 Position: 154 Binlog_Do_DB: dev Binlog_Ignore_DB: mysql,information_schema,performance_schema,sys Executed_Gtid_Set: 1 row in set (0.00 sec) 3: From library 300 Set up my.cnf. [mysqld] lower_case_table_names = 1 # Table names are case insensitive server-id = 300 master_info_repository = table relay_log_info_repository = table datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid Set the master database information #mysql -uroot -p # password: xxxxxx # Set the master database information# mysql> CHANGE MASTER TO # ->MASTER_HOST='192.168.194.3', # ->MASTER_PORT=3306, MASTER_USER='slave', # ->MASTER_PASSWORD='root1234', # ->MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=886 for channel '100'; # mysql> CHANGE MASTER TO # ->MASTER_HOST='192.168.194.4', # ->MASTER_PORT=3306, MASTER_USER='slave', # ->MASTER_PASSWORD='root1234', # ->MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=154 for channel '200'; # Set the master database information# mysql> flush privileges; # start slave; # mysql>show slave status \G Identification synchronization success
test. Random main database: create a table and insert a piece of data. CREATE TABLE `t_user` ( `id` varchar(32) NOT NULL COMMENT 'Primary key ID', `name` varchar(32) CHARACTER SET utf8mb4 NULL COMMENT 'User name', `code` varchar(32) CHARACTER SET utf8mb4 NULL COMMENT 'User code', `phone_number` varchar(300) CHARACTER SET utf8mb4 NULL COMMENT 'Phone number', `create_date` datetime NULL COMMENT 'Creation time', `update_date` datetime NULL COMMENT 'Modification time', PRIMARY KEY (`id`) ) COMMENT = 'User information table'; INSERT INTO t_user (`id`, `name`, `code`, `phone_number`, `create_date`, `update_date`) VALUES ('userId_4', '张三', '123456789', '123456789632', '2020-04-27 22:05:00', '2020-04-27 22:05:00'); Query from library SELECT * FROM t_user; ------+--------+----------+--------------+---------------------+-------------+ | id | name | code | phone_number | create_date | update_date | +-------+--------+----------+--------------+---------------------+----------+ | userId_4 | Zhang San|123456789|123456789632|2020-04-27 22:05:00|2020-04-27 22:05:00 SummarizeThis concludes this article about the implementation ideas and steps of MySQL master-slave construction (multiple masters and one slave). For more relevant MySQL master-slave construction 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:
|
<<: Design Theory: Hierarchy in Design
>>: How to add color mask to background image in CSS3
This article uses examples to describe the common...
Table of contents 1. Introduction 2. select 2.1 Q...
console.log( [] == ![] ) // true console.log( {} ...
Reference Documentation Official Docker installat...
1. Experimental description In the virtual machin...
Table of contents 1. Introduction to Compose 2. C...
W3Cschool explains it this way The <meta> el...
Code: Copy code The code is as follows: <!DOCTY...
I don’t know if you have ever encountered such a ...
Table of contents 1. Single database backup 2. Co...
Without further ado, I will post the code for you...
This article uses examples to describe how to bac...
Quickly install the tensorflow environment in Doc...
<br />Original link: http://www.dudo.org/art...
What is a mata tag The <meta> element provi...