当前位置:网站首页>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

边栏推荐
- 2022/7/18 exam summary
- B title: razlika priority queue approach
- BGP routing principle
- Kotlin operator
- Two ways to monitor the change of user points
- Nodejs2day(nodejs的模块化,npm下载包,模块加载机制)
- 分享高压超低噪声LDO测试结果(High Voltage Ultra-low Noise LDO)
- 2022 national vocational college skills competition "network security" competition question file upload penetration test answer flag
- Shell programming
- Shell homework the next day
猜你喜欢

Beauty naked chat for a while, naked chat over the crematorium!

Shell programming

Super nice navigation page (static page)

Take out brother is the biggest support in this society

On some concepts involved in journal papers compilation + journal query methods

CV learning notes (optical flow)
Share high voltage ultra low noise LDO test results

SPSS uses kmeans, two-stage clustering and RFM model to study the behavior law data of borrowers and lenders in P2P network finance

Burp suite Chapter 7 how to use burp scanner

Why reserve a capacitor station on the clock output?
随机推荐
23.2 customizing the banner control display hidden banner modify banner
Flutter distribution
Date and time function of MySQL function summary
Basic configuration of BGP
A little awesome, 130000 a month+
QT uses QSS to make a beautiful login interface (hand-in-hand teaching)
Differences and connections of previewkeydown, Keydown, keypress and Keyup in C WinForm
Inaccurate problem of flutter fijkplayer seekto
Burp suite Chapter 7 how to use burp scanner
2022/7/11 exam summary
Shell homework the next day
sed作业
2022/7/12 exam summary
QT note 2
2022年全国职业院校技能大赛“网络安全”竞赛试题文件上传渗透测试答案Flag
Random distribution learning notes
JS工具函数大全
Dear teachers, how can sqlserver get DDL in flinkcdc?
Awk operation
Problems caused by slivereappbar