1. Introduction, download and installation of Mycat2

Chapter 1 Getting Started Overview
1.1 What is
Mycat is a database middleware.
1. Database middleware
Middleware: It is a kind of computer software that connects software components and applications to facilitate communication between software components
.
Examples: Tomcat, web middleware.
Database middleware: connect java application program and database
2. Why use Mycat?
1 Java is tightly coupled with the database.
2 High traffic and high concurrency put pressure on the database.
3 Inconsistent read and write request data
3. Comparison of database middleware
insert image description here
1. Cobar belongs to the Ali B2B business group. It started in 2008 and served in Ali for more than 3 years. It has taken over the schema of 3000+ MySQL
databases , and the cluster processes online SQL requests every day. More than 5 billion times. Due to the departure of the Cobar originator,
Cobar ceased maintenance.
2. Mycat is a secondary development of the open source community on the basis of Ali cobar, which solves the problems existing in cobar and
adds many new functions to it. the student surpasses the master.
3. OneProxy is developed based on MySQL's official proxy idea using c, and OneProxy is a commercially charged
middleware. Abandoned some functions, focusing on performance and stability.
4. Kingshard is developed by a small team using the go language, and it still needs to be developed and improved.
5. Vitess is used in Youtube production, and the structure is very complicated. It does not support the MySQL native protocol, and requires a lot of
modification costs to use it.
6. Atlas is rewritten by the 360 ​​team based on mysql proxy, the function needs to be improved, and it is unstable under high concurrency.
7. MaxScale is a middleware developed by mariadb (a version maintained by the original author of MySQL)
8.MySQLRoute is a middleware released by MySQL's official Oracle company

Mycat's official website
http://www.mycat.org.cn/
1.2 What to do
1. Separation of reading and writing
insert image description here
2. Vertical splitting of data fragmentation
(sub-database), horizontal splitting (sub-table), vertical + horizontal splitting (sub-database)
insert image description here
3. Multi-data source integration 1.3
insert image description here
Principle
The most important verb in the principle of Mycat is "intercept", which intercepts the SQL
statement , and first makes some specific analysis on the SQL statement: Shard analysis, routing analysis, read-write separation analysis,
cache analysis, etc., and then send this SQL to the real database at the back end, and properly process the returned results, and
finally return them to the user.
insert image description here
This method decouples the distribution of the database from the code, and the programmer cannot detect whether
Mycat or MySQL is used in the background.

Chapter 2 Installation and Startup
2.1 Installation
1. Download the installation package
Download the corresponding tar installation package and the corresponding jar package
tar (zip) package:
http://dl.mycat.org.cn/2.0/install-template/mycat2- install-template1.20.zip
jar
package:
http://dl.mycat.org.cn/2.0/1.21-release/ (download the latest jar package)
download the required fat jar of mycat2, a jar with a general size of 100mb Files
Put this jar into the mycat\lib folder in the decompressed tar
insert image description here
insert image description here
2. It can be used after decompression
Copy the integrated folder to /usr/local/ under linux 3. Modify
insert image description here
the permissions of the folder and the following files
Otherwise, an error will be reported due to insufficient permissions when running the startup command.
insert image description here
2.2 Startup
1. Add a user in the mysql database connected to mycat
Create a user, the user name is mycat, the password is 123456, and the permissions are assigned as follows:

CREATE USER 'mycat'@'%' IDENTIFIED BY '123456';
--必须要赋的权限mysql8才有的
GRANT XA_RECOVER_ADMIN ON *.* TO 'root'@'%';
---视情况赋权限
GRANT ALL PRIVILEGES ON *.* TO 'mycat'@'%' ;
flush privileges;

2. Modify the prototype configuration of mycat
Before starting mycat, you need to confirm the mysql database configuration corresponding to the prototype data source, and modify the corresponding
user (user), password (password), and ip in the url

…
vim conf/datasources/prototypeDs.datasource.json
{
    
    
"dbType":"mysql",
"idleTimeout":60000,
"initSqls":[],
"initSqlsGetConnection":true,
"instanceType":"WRITE",
"maxCon":1000,
"maxConnectTimeout":3000,
"maxRetryCount":5,
"minCon":1,
"name":"prototypeDs",
"password":"123123",
"type":"JDBC",
"url":"jdbc:mysql://localhost:3306/mydb1?useUnicode=true&serverTimezone=Asi
a/Shanghai&characterEncoding=UTF-8",
"user":"root",
"weight":0
}

3. Verify the database access status
Mycat, as the database middleware, needs to be deployed on different machines from the database, so the remote access
status needs to be verified.

mysql -uroot -p123123 -h 192.168.140.100 -P 3306
mysql -uroot -p123123 -h 192.168.140.99 -P 3306
#如远程访问报错,请建对应用户
grant all privileges on *.* to root@'缺少的host' identified by '123123';

4. Start the mycat
linux startup command

cd mycat/bin
./mycat start
./mycat status
./mycat start 启动
./mycat stop 停止
./mycat console 前台运行
./mycat install 添加到系统自动启动(暂未实现)
./mycat remove 取消随系统自动启动(暂未实现)
./mycat restart 重启服务
./mycat pause 暂停
./mycat status 查看启动状态…

2.3 Login
1. Login to the background management window
This login method is used to manage and maintain Mycat

mysql -umycat -p123456 -P 9066
#常用命令如下:
show database

insert image description here

help;

insert image description here
2. Login data window
This login method is used to query data through Mycat, we choose this method to access Mycat

mysql -umycat -p123456 -P 8066

Guess you like

Origin blog.csdn.net/weixin_45817985/article/details/132603153