Installing and Configuring MyCat2 Distributed Database Middleware
MyCat2 functions as a distributed SQL middleware that provides automatic data sharding across multiple backend databases. It speaks the MySQL protocol and integrates with Java-based data sources. This guide walks through the initial setup on a CentOS 7 environment.
1. Obtain the Distribution
Fetch the installation template and the required JAR with dependencies. Adjust the version number if a newer release is available.
mkdir -p /data && cd /data
wget http://dl.mycat.org.cn/2.0/install-template/mycat2-install-template-1.21.zip
# install unzip if missing
yum install -y unzip
unzip mycat2-install-template-1.21.zip
cd /data/mycat/lib/
wget http://dl.mycat.org.cn/2.0/1.21-release/mycat2-1.21-release-jar-with-dependencies.jar
2. Define a Prototype Data Source
MyCat2 cannot start without atleast one data source definition. Edit prototypeDs.datasource.json to point to a reachable MySQL instance (version 5.7 or 8.0). The actual sharded schemas will be configured later.
vi /data/mycat/conf/datasources/prototypeDs.datasource.json
Update the url, user, and password fields inside the JSON to match your MySQL credentials. Ensure the target database server allows remote connections and that the user has appropriate privileges.
3. Launch the MyCat2 Process
Install a Java runtime and set executable permissions on the management scripts.
yum install -y java
chmod u+x /data/mycat/bin/*
Optionally, modify the default user credentials by editing the root user definition:
vi /data/mycat/conf/users/root.user.json
Now start the service:
/data/mycat/bin/mycat start
Wait about 30 seconds, then check the status:
/data/mycat/bin/mycat status
# Expected output: mycat2 is running (12437).
If the process fails to start, inspect the log:
tail -f /data/mycat/logs/wrapper.log
To stop MyCat2 safely later:
/data/mycat/bin/mycat stop
4. Verify Connectivity
Use a MySQL-compatible client (such as Navicat or the mysql command-line tool) to connect to MyCat2's proxy port.
- Host: IP address of the server
- Port:
8066(can be changed in/data/mycat/conf/server.json; a restart is required after modification) - Username / Password: as defined in
/data/mycat/conf/users/root.user.json
A successful connection indicates that MyCat2 is propertly installed. From here, you can proceed to define logical schemas and sharding rules.