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.
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.
MySQL Environment Setup
1. MySQL host addresses: 192.168.1.235, 192.168.1.237
2. The mycat_demo database on both hosts must have identical tables; ensure the schemas are the same.
Table structure:
MyCat Configuration
Configuration files are located in the /conf directory. Edit the highlighted files.
1. Edit server.xml to set the username and password for connecting to MyCat.
The schemas element defines logical databases; here a logical database MYCAT_DEMO is configured.
2. Edit schema.xml to configure logical databases and tables.
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.
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.
3. Edit rule.xml to configure routing rules.
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.
Run startup_nowrap.bat by double‑clicking it.
If no errors appear, MyCat has started successfully.
You can connect to MyCat using standard MySQL clients such as Navicat.
Default port: 8066
The logical database and tables defined in schema.xml are visible, behaving just like a regular MySQL instance.
Example c3p0 connection pool configuration (replace the URL with MyCat’s):
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".
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
