Quick installation and simple application of mycat under linux

Go to mycat website first: http://dl.mycat.io/ Download the corresponding version of MYCAT server. I use MYCAT server-1.6.5-release-20180122220033-linux.tar.gz here

Upload to linux server.

Unzip: tar-zxvf Mycat-server-1.6.5-release-20180122220033-linux.tar.gz will generate a MYCAT folder.

Here is a simple demonstration of mycat's single database horizontal split table instance using id modulus. Most of our online split table schemes are of this kind.

Modify the server.xml in the conf directory as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 
	- you may not use this file except in compliance with the License. - You 
	may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 
	- - Unless required by applicable law or agreed to in writing, software - 
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
	License for the specific language governing permissions and - limitations 
	under the License. -->
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
	<system>
		<property name="defaultSqlParser">druidparser</property>
    </system>
	
    <user name="root">
        <property name="password">root</property>
        <property name="schemas">tanlei</property>
    </user>

</mycat:server>
Where name="root" and password="root" correspond to the user name and password of mysql instance, and schema corresponds to the name tag of < schema > under schema.xml.

Modify schema.xml as follows:

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">

	<schema name="tanlei" checkSQLschema="false" sqlMaxLimit="100"> 
		<table name="t_user" subTables="t_user$1-3" dataNode="dn1" rule="mod-long" /> 
	</schema> 
	<dataNode name="dn1" dataHost="localhost1" database="tanleidb" /> 
	<dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"  writeType="0" dbType="mysql" 
	 dbDriver="native" switchType="1" slaveThreshold="100"> 
		<heartbeat>select user()</heartbeat>
		<writeHost host="hostM1" url="localhost:3306" user="root" password="root" /> 
	</dataHost>

</mycat:schema>
Modify rule.xml as follows
<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 
	- you may not use this file except in compliance with the License. - You 
	may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 
	- - Unless required by applicable law or agreed to in writing, software - 
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
	License for the specific language governing permissions and - limitations 
	under the License. -->
<!DOCTYPE mycat:rule SYSTEM "rule.dtd">
<mycat:rule xmlns:mycat="http://io.mycat/">
	<tableRule name="mod-long">
		<rule>
			<columns>id</columns>
			<algorithm>mod-long</algorithm>
		</rule>
	</tableRule>
	<function name="mod-long" class="io.mycat.route.function.PartitionByMod">
		<!-- how many data nodes -->
		<property name="count">3</property>
	</function>
</mycat:rule>

Enter bin directory and execute:. / mycat start to start mycat server.

Observe mycat.log and wrapper.log in logs directory. If no error is reported, mycat server starts successfully.

Here, I have built a tanneidb Library under the instance, and created three tables respectively:

The primary key is id.

Use navicat to link port root,root,hostip,8066, and then insert the data:

insert into t_user(id,userName,age,createTime,updateTime) values(5,'tanlei',23,now(),now())

explain
select * from t_user where id = 9

It was found that the data with id=9(mod=0, entering Table 1) fell into the t_user1 table.


Tags: mycat xml Apache Linux

Posted on Sun, 03 May 2020 02:41:52 -0400 by phprooky