1)登陆mysql
mysql -u root -p
2)安装keyring插件
INSTALL PLUGIN keyring_file soname 'keyring_file.so';
3)查看keyring插件
show global variables like '%keyring_file_data%';
show plugins;
4)创建加密表
create table test1(
-> id int primary key auto_increment,
-> name varchar(20),
-> key name(name))
-> ENCRYPTION='Y';
5)插入加密表
insert into test1(id,name) values(1,'anm'),(2,'keyring');
6)查看表创建方式
show create table test1;
7)异常情况
keyring_file.so保存在 /usr/lib/mysql/plugin/,如果删除keyring_file.so,则加密表的数据不能打开。
mysql> select * from test1;
ERROR 3185 (HY000): Can't find master key from keyring, please check in the server log if a keyring plugin is loaded and initialized successfully.
参考