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
and authentication
configurations to server.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
- 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 distributed database
DROP DATABASE encrypt_db;
Notice
- Currently,
DROP DATABASE
will only remove the logical 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 a logical distributed database
, so users need to create actual databases in advance.