mysql加密与解密decode与encode乱码解决方法

  • A+
所属分类:系统文档

mysql decode 加密与解密
更新加密
UPDATE card SET test=ENCODE(NAME,'kljlsfjasdf') WHERE id=1;
解密的方法

SELECT DECODE(test,'kljlsfjasdf') FROM card WHERE id=1

乱码则执行
SELECT CAST(BINARY(DECODE(test,'kljlsfjasdf')) AS CHAR CHARACTER SET utf8) AS VALUE FROM card WHERE id=1

 

 

DROP TABLE IF EXISTS `card`;

 

CREATE TABLE `card` (

  `id` int(14) NOT NULL AUTO_INCREMENT,

  `card_id` varchar(18) CHARACTER SET utf8 DEFAULT NULL,

  `name` varchar(20) CHARACTER SET utf8 DEFAULT NULL,

  `test` varchar(255) COLLATE latin1_general_ci DEFAULT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC;

 

/*Data for the table `card` */

 

insert  into `card`(`id`,`card_id`,`name`,`test`) values (1,'52040219770325X064','李四','Œ(S6Š×');

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: