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
As shown in the figure: But when viewed under IE6...
First: First, confirm whether the server hardware ...
1. Meaning of partition table A partition table d...
This article example shares the specific code for...
1. Linux network configuration Before configuring...
Introduction to Linux alarm function Above code: ...
Table of contents 1. Basic overview of the proces...
Table of contents 1. Constructors and prototypes ...
You can save this logo locally as a .rar file and...
Passing values between mini program pages Good ...
Preface If you frequently access many different r...
Preface The apt-get command is a package manageme...
Introduction to Debian Debian in a broad sense re...
I believe that many users who make websites will ...
1. Unzip MySQL 5.7 2. Create a new configuration ...