模块名 | 可用加密算法 | 密钥长度限制 |
---|---|---|
keyring_encrypted_file | AES DSA RSA |
无限制 无限制 无限制 |
keyring_file | AES DSA RSA |
无限制 无限制 无限制 |
keyring_okv | AES | 16, 24, 32 |
keyring_aws | AES | 16, 24, 32 |
总结一下,四种方案都是文件加密,内存解密方案,区别在于加解密的key存放方案。推荐使用keyring_okv和keyring_aws,并确保mysql账户的安全性和严格区分账户权限。
另外2种安全性不大。
实施步骤
OK,现在简单讲一下最简单的keyring_file部署方案,提前说明下windows貌似无法使用这种方案,因为不知道为什么加密用的key总是无法生成。
1.使用最新版的mysql 5.7.21
使用yum apt 之类的工具安装最新版的mysql 或者 下载源码自行编译安装
sudo apt install mysql-5.7
2.启用加密模块
INSTALL PLUGIN keyring_file soname ‘keyring_file.so';
mysql> INSTALL PLUGIN keyring_file soname 'keyring_file.so'; Query OK, 0 rows affected (0.10 sec)
3.设置加密key存放路径
set global keyring_file_data='/root/mysql-keyring/keyring';
mysql> set global keyring_file_data='/var/lib/mysql-keyring/keyring'; Query OK, 0 rows affected (0.00 sec)
4.永久启用设置
上诉两个步骤都是临时的,重启服务都会失效,我们把配置写到配置文件里,确保重启服务后也能生效
[mysqld] early-plugin-load=keyring_file.so keyring_file_data=/root/mysql-keyring/keyring
5.查看key的存放路径
show global variables like ‘%keyring_file_data%';
mysql> show global variables like '%keyring_file_data%'; +-------------------+--------------------------------+ | Variable_name | Value | +-------------------+--------------------------------+ | keyring_file_data | /var/lib/mysql-keyring/keyring | +-------------------+--------------------------------+ 1 row in set (0.00 sec)
6.查看启用的模块
查看下keyring_file模块是否已经被载入。
show plugins;
mysql> show plugins; +----------------------------+----------+--------------------+-----------------+---------+ | Name | Status | Type | Library | License | +----------------------------+----------+--------------------+-----------------+---------+ | binlog | ACTIVE | STORAGE ENGINE | NULL | GPL | | mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL | | sha256_password | ACTIVE | AUTHENTICATION | NULL | GPL | | PERFORMANCE_SCHEMA | ACTIVE | STORAGE ENGINE | NULL | GPL | | CSV | ACTIVE | STORAGE ENGINE | NULL | GPL | | MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | | MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | | InnoDB | ACTIVE | STORAGE ENGINE | NULL | GPL | | INNODB_TRX | ACTIVE | INFORMATION SCHEMA | NULL | GPL | | INNODB_LOCKS | ACTIVE | INFORMATION SCHEMA | NULL | GPL | | INNODB_LOCK_WAITS | ACTIVE | INFORMATION SCHEMA | NULL | GPL | | INNODB_CMP | ACTIVE | INFORMATION SCHEMA | NULL | GPL | | INNODB_CMP_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL | 。。。。。。(省略N条) | keyring_file | ACTIVE | KEYRING | keyring_file.so | GPL | +----------------------------+----------+--------------------+-----------------+---------+ 45 rows in set (0.00 sec)
7.加密现有的表
alter table table encryption='Y';
mysql> create table cc (id int); Query OK, 0 rows affected (0.01 sec) mysql> alter table cc encryption='Y'; Query OK, 0 rows affected (0.06 sec) Records: 0 Duplicates: 0 Warnings: 0
8.取消加密
alter table table encryption='N';
mysql> alter table cc encryption='N'; Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0
官方文档:
https://dev.mysql.com/doc/refman/5.7/en/keyring-installation.html
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。