server.xml Overview
server.xml is MyCat’s core configuration file, storing almost all system configuration information needed by MyCat.
Main Configuration Contents
1. System Parameters Configuration
- MyCat service port (default 8066)
- Management port (default 9066)
- Character set configuration
- Thread pool size
- Connection timeout
2. User Permission Configuration
- Define username and password for accessing MyCat
- Set user permissions (such as read-only, read-write permissions)
- Configure schemas accessible by users
3. Firewall Configuration
- Set IP whitelist/blacklist
- Configure SQL interception rules
- Define SQL injection protection strategies
4. Performance Tuning Parameters
- Buffer size settings
- Connection pool configuration
- Transaction processing parameters
Global Sequence Number
In the context of implementing database sharding, database auto-increment primary keys cannot guarantee global uniqueness of auto-increment primary keys. MyCat provides multiple global sequence implementation methods:
0 - File Storage Method
Store data in local file system in file form.
1 - Database Storage Method
Use relational database for data storage.
2 - Local Timestamp Method
ID uses 64-bit binary format:
- Timestamp section: 42 bits, precise to millisecond level
- Machine identifier section: 5 bits, supports up to 32 machines
- Business code section: 5 bits, supports 32 business types
- Sequence number section: 12 bits, can generate 4096 sequence numbers per millisecond
3 - ZK and Local Configuration Distributed ID Generator
- ZooKeeper cluster maintains global configuration
- Local cache worker node information
4 - ZooKeeper Increment Method
Generate incrementing IDs through ZooKeeper’s ordered nodes.
Configuration Example
<!-- User configuration example -->
<user name="user">
<property name="password">user</property>
<property name="schemas">wzk_order</property>
</user>