使用指定的密码对待加密字符串进行加密操作。
ENCODE(str, pass_str)
str 待加密字符串
pass_str 加密密码
该示例使用密码 aaaaaa 对字符串 “hello world” 进行加密,如下:
mysql> select hex(encode('hello world', 'aaaaaa'));
+--------------------------------------+
| hex(encode('hello world', 'aaaaaa')) |
+--------------------------------------+
| A9880C540F2CFDBA54F044 |
+--------------------------------------+
1 row in set (0.04 sec)注意:encode() 函数加密后输出的结果是二进制,需要借助 hex() 函数使用十六进制显示,否则在控制台显示乱码,不可读。例如:
mysql> select encode('hello world', 'aaaaaa');
+---------------------------------+
| encode('hello world', 'aaaaaa') |
+---------------------------------+
| ��T,��T�D |
+---------------------------------+
1 row in set (0.05 sec)