Databases 7 min read

How to Install, Configure, and Run MyCat for MySQL Sharding on Windows

This guide walks you through downloading MyCat, setting up the MySQL environment, configuring server.xml, schema.xml, and rule.xml for sharding, and starting MyCat on Windows, including connection details and sample c3p0 pool configuration, with screenshots for each step.

Java Backend Technology
Java Backend Technology
Java Backend Technology
How to Install, Configure, and Run MyCat for MySQL Sharding on Windows

Official Resources

MyCat official website: http://www.mycat.io/

MyCat authoritative guide: http://www.mycat.io/document/Mycat_V1.6.0.pdf

MyCat download page: http://dl.mycat.io/

MyCat Download

After downloading, unzip the package.

MyCat directory structure
MyCat directory structure

MySQL Environment Setup

1. MySQL host addresses: 192.168.1.235, 192.168.1.237

MySQL host list
MySQL host list

2. The mycat_demo database on both hosts must have identical tables; ensure the schemas are the same.

Database tables
Database tables

Table structure:

Table schema
Table schema

MyCat Configuration

Configuration files are located in the /conf directory. Edit the highlighted files.

Configuration directory
Configuration directory

1. Edit server.xml to set the username and password for connecting to MyCat.

server.xml snippet
server.xml snippet

The schemas element defines logical databases; here a logical database MYCAT_DEMO is configured.

2. Edit schema.xml to configure logical databases and tables.

schema.xml snippet
schema.xml snippet

In MyCat, a schema is a logical database; under it, table elements define logical tables. Example:

<table name="event" primaryKey="eventid" dataNode="dn1,dn2" rule="sharding-by-murmur" />

This defines a logical table event with primary key eventid, using data nodes dn1 and dn2 and the sharding-by-murmur rule.

Data node definition example:

<dataNode name="dn1" dataHost="db235" database="mycat_demo" />

The name attribute matches the dataNode referenced in the table, dataHost specifies the physical MySQL server, and database is the actual database on that server.

dataNode configuration
dataNode configuration

For the above dataHost, all reads and writes are directed to host 192.168.1.235.

For more parameters, refer to the MyCat authoritative guide.

Additional configuration
Additional configuration

3. Edit rule.xml to configure routing rules.

rule.xml snippet
rule.xml snippet

The logical table event uses the sharding-by-murmur rule, which is a consistent hash algorithm.

– colums: the sharding column, here eventid ; – property->count: the number of shards (data nodes) defined in schema.xml , here 2.

The provided rule.xml already contains the necessary rule; no further changes are required.

The relationship between tags is straightforward: the algorithm element’s murmur corresponds to the function name.

Starting MyCat

On Windows, the startup script is located in the /bin directory.

bin directory
bin directory

Run startup_nowrap.bat by double‑clicking it.

startup script
startup script

If no errors appear, MyCat has started successfully.

You can connect to MyCat using standard MySQL clients such as Navicat.

Navicat connection
Navicat connection

Default port: 8066

Port configuration
Port configuration

The logical database and tables defined in schema.xml are visible, behaving just like a regular MySQL instance.

Schema view
Schema view

Example c3p0 connection pool configuration (replace the URL with MyCat’s):

c3p0 configuration
c3p0 configuration

With this, the MyCat installation and basic usage are complete. For advanced features, consult the MyCat authoritative guide.

For more MyCat learning resources, follow the WeChat public account "Java后端技术" and send the keyword "MyCat".

WeChat QR code
WeChat QR code
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

shardingConfigurationmysqlDatabase MiddlewareMycat
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.