MyCAT debugging environment setup

1. Dependent tools

  • Maven
  • Git
  • JDK
  • MySQL
  • IntelliJ IDEA

2. Source code pull

From the official repository  https://github.com/MyCATApache/Mycat-Server 

Fork out of its own warehouse. Why Fork ? Now that we have started to read and debug the source code, we may write some comments and have our own repository, which can be freely submitted.

Use   pull code IntelliJ IDEA from  the outgoing repository. ForkAfter the pull is complete, Maven the dependency package will be downloaded, which may take some time, please wait patiently.

3. Database configuration

What we want to build is a debugging environment for non-sharded tables, we need to create a database and table:

  1. Create database: db01 .
  2. Create database tables: travelrecord .
CREATE TABLE `travelrecord` (

`id` bigint(20) NOT NULL AUTO_INCREMENT,

`name` varchar(255) CHARACTER SET latin1 DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_bin

4. MyCAT configuration

In order to avoid affecting the implementation source code, we choose to  test make changes to the directory.

1.  resources Create a new folder in the directory,  and move all the backups original  resources files to  backups the next, so that our environment will be clean.
2.  resources Create a new file in the directory  schema.xml , configure  MyCAT the logical library, table, data node, and data source.

<?xml version="1.0"?>

<!DOCTYPE mycat:schema SYSTEM "schema.dtd">

<mycat:schema xmlns:mycat="http://io.mycat/">

<schema name="dbtest" checkSQLschema="true" sqlMaxLimit="100">

<table name="travelrecord" dataNode="dn1" autoIncrement="true" primaryKey="id" />

</schema>

<dataNode name="dn1" dataHost="localhost1" database="db1" />

<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="127.0.0.1:33061" user="root" password="123456"> <!-- ‼️‼️‼️ url、user、password 设置成你的数据库 -->

</writeHost>

</dataHost>

</mycat:schema>

3.  Create a new  file  in the resources directory to  configure the  system configuration.server.xmlMyCAT

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mycat:server SYSTEM "server.dtd">

<mycat:server xmlns:mycat="http://io.mycat/">

<system>

<property name="nonePasswordLogin">0</property> <!-- 0为需要密码登陆、1为不需要密码登陆 ,默认为0,设置为1则需要指定默认账户-->

<property name="useHandshakeV10">1</property>

<property name="useSqlStat">0</property> <!-- 1为开启实时统计、0为关闭 -->

<property name="useGlobleTableCheck">0</property> <!-- 1为开启全加班一致性检测、0为关闭 -->

<property name="sequnceHandlerType">2</property>

<property name="processorBufferPoolType">0</property>

<property name="handleDistributedTransactions">0</property>

<property name="useOffHeapForMerge">1</property>

<property name="memoryPageSize">64k</property>

<property name="spillsFileBufferSize">1k</property>

<property name="useStreamOutput">0</property>

<property name="systemReserveMemorySize">384m</property>

<property name="useZKSwitch">false</property>

</system>

<user name="root" defaultAccount="true">

<property name="password">123456</property>

<property name="schemas">dbtest</property>

</user>

</mycat:server>

5. MyCAT starts

1.  java Create a new package in the directory  debugger to distinguish it from the existing package.
2.  debbuger Create a new one under the package  MycatStartupTest.java :

package debugger;

import io.mycat.MycatStartup;

/**

* {@link io.mycat.MycatStartup}测试

*

* Created by yunai on 2017/5/22.

*/

public class MycatStartupTest {

    public static void main(String[] args) {

        MycatStartup.main(args);

    }

}

3. Run  MycatStartupTest.java , when you see the output log, MyCAT Server startup successfully. see logs in logs/mycat.log the startup is successful.

As of now, the test directory is as follows:

test directory.png

6. MyCAT Test

The debugging environment has been built, let's see if it is correct.

Connect using the  MySQL client  MyCAT :

  • HOST :127.0.0.1
  • PORT :8066
  • USERNAME :root
  • PASSWORD :123456
mysql> insert into travelrecord(name) values ('haha');

Query OK, 1 rows affected (0.01 sec)

mysql> select * from travelrecord;

+--------------------+------+

| id | name |

+--------------------+------+

| 866707181398003712 | haha |

+--------------------+------+

1 rows in set (0.05 sec)

success.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325169779&siteId=291194637