Encrypt
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 encrypt_db;
- Use newly created database
USE encrypt_db;
- Configure data source information
ADD RESOURCE ds_0 (
HOST=127.0.0.1,
PORT=3306,
DB=ds_0,
USER=root,
PASSWORD=root
);
- Create encrypt table
CREATE TABLE `t_encrypt` (
`order_id` int NOT NULL,
`user_plain` varchar(45) DEFAULT NULL,
`user_cipher` varchar(45) DEFAULT NULL,
PRIMARY KEY (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
- Create encrypt rule
CREATE ENCRYPT RULE t_encrypt (
COLUMNS(
(NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,TYPE(NAME=AES,PROPERTIES('aes-key-value'='123456abc'))),
(NAME=order_id, CIPHER =order_cipher,TYPE(NAME=MD5))
));
- Alter encrypt rule
CREATE ENCRYPT RULE t_encrypt (
COLUMNS(
(NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,TYPE(NAME=AES,PROPERTIES('aes-key-value'='123456abc'))),
));
- Drop encrypt rule
DROP ENCRYPT RULE t_encrypt;
- Drop resource
DROP RESOURCE ds_0;
- Drop distributed database
DROP DATABASE encrypt_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 .