当前位置:网站首页>MySQL single database and table splitting using MYCAT

MySQL single database and table splitting using MYCAT

2022-06-23 13:30:00 InfoQ

One 、Mycat Installation and deployment
Get ready :
Installation environment Linux
mycat Runtime needs java development environment , So you need to install JDK
Before installation, check if the system comes with your own open-jdk
command :
rpm -qa |grep java
rpm -qa |grep jdk
rpm -qa |grep gcj
If no information is entered, it means no installation .
If installed, you can use
rpm -qa | grep java | xargs rpm -e --nodeps 
Bulk unload all with Java The file of     The key word of this command is
java
First retrieve contains java A list of
yum list java*  retrieval 1.8 A list of
yum list java-1.8*
    install 1.8.0 All files for
yum install java-1.8.0-openjdk* -y
Use the command to check if the installation is successful
java -version
install mycat
mycat It's from 1.6.5 The version supports single database and table splitting . You can choose the appropriate version according to your own needs
download Mycat 1.6.5 wget http://dl.mycat.io/1.6.5/Mycat-server-1.6.5-release-20171029183033-linux.tar.gz 
After decompressing , Modify the configuration file , stay mycat/conf Next
Mycat Is a database middleware , It does not have the function of data storage , It can be simply understood as an intermediary agent , It is equivalent to an intermediary or errand boy . Help you integrate data processing , So in order to realize data storage , Support for deploying physical databases is required , Need to install MySQL( This is when you have installed MySQL, I won't repeat MySQL Installation ).
1. modify server.xml

null

Set up user name,password And schemas,  name and password To be in Mycat Connect MySQL Database ,schemas It's the logic library , Want to be with schema.xml Inside schema name Corresponding .
2. modify schema.xml

null

Pictured ,schema name Want to be with server.xml Corresponding upper ,user The table is divided into ten tables , You can only set one datanote,rule Adopt mold taking mode mod-long.writeHost and readHost Set to the same database .
3. modify rule.xml

null
The default is selected this time mod-long The rules , Only need to modify count Count , Corresponding upper subTables Just count .

modify property count  be equal to 10.
such , Configuration is complete .
Two 、 start-up Mycat And connections MySQL

First in MySQL On the library , build 10 A watch ,user1-user10.
1. Get into Mycat Under bag bin Catalog , start-up Mycat   
./mycat start
2. Connect MySQL  

null
mysql -utest -ptest -h127.0.0.1 -P8066 -Dzhenxui
3. Inquire about Mycat user

null

4. Query sub table

null

10 Zhang Zibiao found out all of them
5. To the library insert data

null

null

null
Previously inserted 40 Data .  As can be seen from the picture ,50 Pieces of data are equally distributed to 10 On a sub table .
notes : Write it yourself when inserting ID.
thus , Realization MySQL Single database and tables and data sharing .

summary
MySQL Dividing databases and tables is not a necessary step in development , Not required , It depends on your business volume and other comprehensive factors , When there is too much data in your data table, resulting in a file that is too large , You can use the corresponding strategy to slice according to the specific situation of data storage , This can avoid large changes to the code or even solve the problem without changing the code . If you use sub database and sub table according to the policy , The project needs to be modified , And the sub table also increases the complexity of data reading , In particular, multi table joint query . The other thing to note is that , If the time comes when we have to divide the databases and tables , The strategy of designing sub database and sub table must be long-term , Think carefully , In response to subsequent business changes
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231100461808.html

随机推荐