Introduction of 1.Mycat
Mycat database middleware
Effect: 1, two separate read and write data partitioning (split vertically sub-libraries, sub-table horizontal split, vertical split horizontally split +) 3, integration of multiple data sources
Principle: that interception (like nginx )
- mycat installation and startup
- The mycat installation package to extract / opt directory
- After extracting the copy mycat folder to / usr / local / directory
cp -r ./mycat /usr/local
- Modify mycat configuration files in the installation directory
First, enter the installation directory cd / usr / local / mycat / conf
Modify server.xml file (user-defined variables and related systems)
Second . Modify the schema.xml (content definition logical databases, tables, and the like fragmentation node) document
Wherein the schema tag name is a logical name of the library (in server.xml configuration)
Datanode label data indicating nodes in schema before the table shows default dataNode = dn1 data node
<dataNode> tag is a tag showing data node, name attribute data is the name of the current node, DataHost represents points <dataHost label >
database corresponding to mysql database on
<dataHost label > The most important balance property . Set mycat load On balance type
<writeHost> indicate which machine to act as host to write
<reatHost> indicate which machine to act as the host read
Verify your database access the situation before starting . To see if the user has permission to access
mysql -uroot -proot -h native ip address -P 3306
mysql -uroot -proot -h virtual machine IP address -P 3306
The machine as a remote access error, please build the corresponding user (a user given rights to connect remotely)
. grant all privileges on * * to root @ ' lack of host' identified by '123123';
Before starting the mysql must have a corresponding written in the configuration file database database, should not, before the start mysql create the corresponding database host
- Start mycat Service
Method 1: Start the console: mycat console next to mycat / bin directory
Second way: the background to start: go mycat mycat start / bin directory
See successful start on it
- Log on to mycat program
6. You can view mycat the database (just one server.xml configuration logic library)
At this time, myCat environment has set the stage (a master-slave,)
mycat built environment is to be provided to build a good mysql master copy from
- Separate read and write.
If the read and write operation requires only separation schema.xml modified file balance value of the property
The type of load balancing, the current value has 4 kinds:
1. balance = "0", do not open the separate read and write mechanism, a read operation is sent to all currently available writeHost on.
Balance = 2. ". 1" , all readHost and stand by writeHost participation select load balancing statement, simply, when the dual master-slave mode bis (Ml-> Sl , M2-> S2 , and M1 and M2 mainly among equipment ) , under normal circumstances, M2, S1, S2 are involved in select load balancing statement.
Balance = 3. "2" , all read operations are random in writeHost , readhost distribution on.
Balance = 4. ". 3" , all the read requests to the random distribution readhost performed, writerHost does not bear the pressure reading
How to view the query using a master or slave?
Execute INSERT INTO table VALUES (3, @@ hostname) in the host database; statements
In this case mycat lookup table, it can be seen mycat logic table TESTDB separate read and write is not used, then
You need to balance the value of property in schema.xml file
After correction in the balance restart mycat can see the effect of the separate read and write
In mycat view the host name of the table below, you can verify whether it is a separate read and write
Above balance value I set 2, randomly read data from the master and slave.