readwrite_splitting
Usage
Pre-work
- Start the MySQL service
- Create MySQL database (refer to ShardingProxy data source configuration rules)
- Create a role or user with creation permission for ShardingProxy
- Start Zookeeper service (for persistent configuration)
Start ShardingProxy
- Add
mode
andauthentication
configurations toserver.yaml
(please refer to the example of ShardingProxy) - Start ShardingProxy (Related introduction)
Create a distributed database and sharding tables
- Connect to ShardingProxy
- Create a distributed database
CREATE DATABASE readwrite_splitting_db;
- Use newly created database
USE readwrite_splitting_db;
- Configure data source information
ADD RESOURCE write_ds (
HOST=127.0.0.1,
PORT=3306,
DB=ds_0,
USER=root,
PASSWORD=root
),read_ds (
HOST=127.0.0.1,
PORT=3307,
DB=ds_0,
USER=root,
PASSWORD=root
);
- Create readwrite_splitting rule
CREATE READWRITE_SPLITTING RULE group_0 (
WRITE_RESOURCE=write_ds,
READ_RESOURCES(read_ds),
TYPE(NAME=random)
);
- Alter readwrite_splitting rule
ALTER READWRITE_SPLITTING RULE group_0 (
WRITE_RESOURCE=write_ds,
READ_RESOURCES(read_ds),
TYPE(NAME=random,PROPERTIES(read_weight='2:0'))
)
- Drop readwrite_splitting rule
DROP READWRITE_SPLITTING RULE group_0;
- Drop resource
DROP RESOURCE write_ds,read_ds;
- Drop distributed database
DROP DATABASE readwrite_splitting_db;
Notice
- Currently,
DROP DATABASE
will only remove thelogical distributed database
, not the user’s actual database. DROP TABLE
will delete all logical fragmented tables and actual tables in the database.CREATE DATABASE
will only create alogical distributed database
, so users need to create actual databases in advance .
当前内容版权归 ShardingSphere 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ShardingSphere .