Mycat uses MySQL's communication protocol to simulate a MySQL server and establishes a complete Schema (database), table(data table),user 's logical model, This logical model is mapped to a real physical library on the back-end storage node Datanode, so that all clients and programming languages that can use MySQL can use Mycat as MySQLServer, without having to develop new clients.
Mycat: When Mycat receives a client-sent SQL request, the SQL is parsed and checked, the results of the analysis are SQL routed, the SQL routing policy supports the traditional table-based sharding fields, and the unique slice strategy based on the database e-r relationship is supported. For SQL routed to multiple data nodes (DataNode), the received DataSet is "merged" and then output to the client.
Datanode is the logical data node of MYCAT, which maps to a datebase of a physical database on the back end, in order to make the system highly available, each datanode can be configured with multiple reference addresses (DataSource), When the primary datasource is detected as unavailable, the system automatically switches to the next available datasource, where datasoure can be considered the address of the main MySQL server.
1. Download the installation package Https://github.com/MyCATApache/Mycat-download/tree/master/1.5-RELEASE
2, configure the environment variables (MYCAT installation package decompression in any way, but to avoid the Chinese path, because we want to configure environment variables )
3, modify the configuration file (the configuration files that need to be modified are in the Conf folder)
(1) Modify wrapper.conf
Configuring the JDK
(2) Modify Server.xml (define user and system related variables, such as ports, etc., is Mycat server parameter adjustment and user authorization configuration file)
Configure the user name and password for the Mycat login
(3) Modify Schema.xml (define logical library, table, shard node, etc.)
Configuration of a global table T_rank, a library table T_user_label, a library rule is sharding-by-murmur (defined in Rule.xml)
Three databases are configured DB1,DB2,DB3
(4) Modify Rule.xml
In the above Schema.xml file defined a library table T_user_label, the library rules are sharding-by-murmur, so to modify the corresponding sub-library field
At the same time, three sub-libraries are defined, so modify
Note: A brief introduction to the Mycat sub-Library rules
Mycat Common shard rules are as follows, and there are other shards that are not all listed here:
(1) Shard enumeration: Sharding-by-intfile
(2) Primary key range conventions: Auto-sharding-long This shard is suitable for, plan ahead the Shard field a range belongs to which Shard
(3) Conformance Hash:sharding-by-murmur
(4) String hash parsing: Sharding-by-stringhash
(5) Shard by Date (day): Sharding-by-date
(6) Split by single month: Sharding-by-hour
(7) Natural Month Shard: Sharding-by-month
(8) Modulo: mod-long This rule is to find the operation of the Shard field
(9) Take model confining constraint: sharding-by-pattern This kind of rule is the combination of modulo operation and scope constraint, which is mainly for the subsequent data migration, that is, the node distribution of data can be determined autonomously.
4. Start Mycat
(1) Create a new 3 database in the original database db1,db2,db3
(2) Start and stop services
Go to cmd. Switch to./mycat/bin/
Note: Installation Mycat service:mycate Install
Start Mycat service:mycate start
Stop Mycat Service:mycate stop
Note: After you modify the configuration file, you need to restart the Mycat service
MYSQL-H[IP]-u[username]-p[password]-p8066
To view a database in 8066, add a table using a database
New Table
Using the Navicat Client connection port is a 8066 user name and password is configured in the Server.xml above
(Note here I made a low-level error, the connection name uses a colon, because the connection name here will be generated in a corresponding folder, so the naming needs to meet the Windows file name specification)
Now that the Mycat configuration is complete, you can try entering the INSERT statement to see that the data meets the sub-Libraries and global tables ...
Windows configuration Mycat