一、先查询数据库的加密模式
select @@session.block_encryption_mode;
二、修改加密模式
set block_encryption_mode = 'aes-128-cbc';
三、加密
update 表名 set 字段名 = to_base64(AES_ENCRYPT(字段名, "1234567890poiuyt","1234567890asdfgh")) where 字段名 not like "%==%";
四、解密
注意:要使用同样的key:1234567890poiuyt ,1234567890asdfgh
update 表名 set 字段名 = AES_DECRYPT(FROM_base64(字段名),"1234567890poiuyt","1234567890asdfgh") where 字段名 like "%==%";
五、测试
TWCgHHOluJt570n29GeZGw== 是加密后的字符串
select AES_DECRYPT(FROM_base64('TWCgHHOluJt570n29GeZGw=='),"1234567890poiuyt","1234567890asdfgh") as DECRYPT;