当前位置:网站首页>Mysql8 one master one slave +mycat2 read write separation
Mysql8 one master one slave +mycat2 read write separation
2022-07-26 08:30:00 【csg103】
One single installation mysql
mkdir /usr/local/mysql && cd /usr/local/mysql/
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.29-1.el7.x86_64.rpm-bundle.tar
tar -xvf mysql-8.0.29-1.el7.x86_64.rpm-bundle.tarinstall
rpm -ivh mysql-community-common-8.0.29-1.el7.x86_64.rpm mysql-community-libs-8.0.29-1.el7.x86_64.rpm mysql-community-libs-compat-8.0.29-1.el7.x86_64.rpm mysql-community-client-8.0.29-1.el7.x86_64.rpm mysql-community-server-8.0.29-1.el7.x86_64.rpm --nodeps --forceinitialization
mysqld --initialize;chown mysql:mysql /var/lib/mysql -R;systemctl start mysqld.service;systemctl enable mysqld;View the default password
cat /var/log/mysqld.log | grep passwordLogin to change password
mysql -uroot -pChange Password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';Remote login authorization
User view
select host, user, authentication_string, plugin from mysql.user;
establish %root
create user 'root'@'%' identified with mysql_native_password by '123456';
For the new root Authorize remote login
GRANT ALL ON *.* TO 'root'@'%';
A master from
192.168.10.30 Lord
192.168.10.31 from
Modify the configuration file vim/etc/my.conf
The following configurations are mainly added
# The primary server is unique ID
server-id = 1
# Start binary log
log-bin = mysql-bin
# Set up the database not to be copied
binlog-ignore-db = mysql
binlog-ignore-db = information_scheam
# Libraries that need to be copied
binlog-do-db = mydb1
# Set up binlog Format Default STATEMENT
# STATEMENT Copy sql But if there is set time=now() In operation Data is delayed The time will be different
# ROW Copy each line There will be no now problem But if sql If the sentence affects too much STATEMENT The execution efficiency will be higher than ROW
# MIXED The above But it can't contain @@ System variables The master-slave replication will be inconsistent
binlog_format = STATEMENTfrom Modify the configuration file and add the following configuration
server-id =2
relay-log =mysql-relayRestart two mysql service
systemctl restart mysqldOn a host Check the host status , After that, there can be no operation If there is The access point will change .
show master status;

Slave Execute the following synchronization code , file and pos Keep the host consistent .
CHANGE MASTER TO MASTER_HOST='192.168.10.30',
MASTER_USER='root',
MASTER_PASSWORD='123456',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=157;Slave execution
start slave; Check the slave status
show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
It means that the master and slave are successful .
test
Host create Library Build table insert data ; Indicates that it must be the table configured for synchronization above .
create database mydb1;
create table mydb1.mytb1(id int,name varchar(50));
insert into mydb1.mytb1 values(1,"gz");
Slave query

If the setup fails You can stop slave synchronization Reset host go back to Slave Execute the following synchronization code Re operate at
stop slave;
reset master;
mycat Read / write separation
build mycat The server , Refer to the previous article .
Connect mycat The server
mysql -uroot -p -h 192.168.10.30 -P 8066stay MYSQL Window execution
Add data sources 1
/*+ mycat:createDataSource{
"name":"dw0",
"url":"jdbc:mysql://192.168.10.30:3306/?useSSL=false&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true",
"user":"root",
"password":"123456"
} */;
Automatically generate configuration files after execution

Add data sources 2
/*+ mycat:createDataSource{
"name":"dr0",
"url":"jdbc:mysql://192.168.10.31:3306/?useSSL=false&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true",
"user":"root",
"password":"123456"
} */;
Create a cluster configuration
/*! mycat:createCluster{"name":"prototype","masters":["dw0"],"replicas":["dr0"]} */;Generate the configuration file after completion

establish mycat Logical library
Execute the script mydb1 Already in mysql There is an entity library , After creation, the library and table will be synchronized automatically Interface
/*+ mycat:createSchema{
"customTables":{},
"globalTables":{},
"normalTables":{},
"schemaName":"mydb1",
"shardingTables":{},
"targetName":"mycluster"
} */;Generate a configuration file after execution

You can see Once the data source matches The mapped logical library will be automatically generated in the logical library ,mycat Operate the database by operating the logical library .
Borrow a picture from the Internet :

test
operation mycat Insert data into the logical library

Master library slave Library You can look it up

边栏推荐
- Template summary
- Oracle 常用函数
- 日常一记(11)--word公式输入任意矩阵
- The most complete network: detailed explanation of six constraints of MySQL
- Uninstallation of dual systems
- Special Lecture 3 number theory + game theory learning experience (should be updated for a long time)
- The first ide overlord in the universe, replaced...
- Vscode utility shortcut
- flex三列布局
- Burp suite Chapter 4 advanced options for SSL and proxy
猜你喜欢

Dev gridcontrol 捕获按键事件

Seq2seq and attention model learning notes

Apple's tough new rule: third-party payment also requires a percentage, and developers lose a lot!

QSS add resource file of QT

Dev gridcontrol captures key events
![[GUI] swing package (window, pop-up window, label, panel, button, list, text box)](/img/05/8e7483768a4ad2036497cac136b77d.png)
[GUI] swing package (window, pop-up window, label, panel, button, list, text box)

A little awesome, 130000 a month+

Kotlin variables and constants

Date and time function of MySQL function summary

2022-7-6 personal qualifying 3 competition experience
随机推荐
Kotlin operator
Redis进阶
Burp Suite - Chapter 2 burp suite proxy and browser settings
The full name of flitter IDFA is identity for advertisers, that is, advertising identifiers. It is used to mark users. At present, it is most widely used for advertising, personalized recommendation,
[endnote] detailed explanation of document template layout syntax
内存管理-动态分区分配方式模拟
ORACLE 官方文档
The second lesson is the construction of development environment
QT uses QSS to make a beautiful login interface (hand-in-hand teaching)
Add in the registry right click to open in vscode
Recurrence of strtus2 historical vulnerability
Date and time function of MySQL function summary
Oracle 常用函数
2022/7/9 exam summary
flink oracle cdc 读取数据一直为null,有大佬知道么
为什么要在时钟输出上预留电容的工位?
Burp suite Chapter 4 advanced options for SSL and proxy
Exam summary on July 13, 2022
The data read by Flink Oracle CDC is always null. Do you know
Kotlin variables and constants