日期:2014-05-16  浏览次数:20673 次

mysql坑爹了,把我一个大活人折腾成白痴了。。。
mysql的encode和decode真能把人折腾疯了
先声明,下面涉及到的操作的字段类型是binary(128)

从dos下执行:
mysql> select encode("1234","1234");
+-----------------------+
| encode("1234","1234") |
+-----------------------+
| %蚦? |
+-----------------------+
1 row in set (0.00 sec)

再执行
mysql> select decode("%蚦?","1234");
+-----------------------+
| decode("%蚦?","1234") |
+-----------------------+
| 123, |
+-----------------------+
1 row in set (0.00 sec)

两个还不一样。好吧,我执行
insert into xxxx values (xxx...encode("1234","1234")...xxx)
然后看到数据库里面多出来的那行内容的密码是
hR W¾½ï|?C6ðsHÖ¾?:ókU¥YFä7?ä?=?&¼¬,|oî?¢=?ÏdÏÊd8ùKrw$D3®k\ë?QØác?bÜÅ?s`*®¬×±<³??`1У8?"´?uZK?"8K¾Ï?ÍzôU(¹åþ?a*?
Ê
好吧,我承认我眼瞎了,到底这是神马?????怎么差了这么大?????
mysql你敢不敢坑爹坑的更厉害点!!!!!
坑爹啊mysql有木有!!!!

然后我尝试想把这一串坑爹的东西粘贴到不管是dos下还是mysqladministrator中,更坑爹的事情出现的:不是报错执行不了,就是粘贴的内容反而干掉了dos前面输进去的内容

好吧,那这样试试 select * from xxxx where xxxxx = encode("1234","1234")看看能不能得到我刚才插进去的东西
结果是得到 
0 rows fetched in 0.0048s  
去你妹的48,4你妹啊!!!!不能忍了!!!!
我刚才插进去的数据就这么莫名其妙没了,可是他喵的明明躺在那里啊

我彻底被mysql折腾成白痴了

我彻底无语了,求大神救救我把

------解决方案--------------------
楼主需要知道,在WINDOWS的命令行下很多时候显示的 ? 并不是真正的 ? 通过下例你可以看到其实是 DF

SQL code
mysql> select encode("1234","1234");
+-----------------------+
| encode("1234","1234") |
+-----------------------+
| %蚦?                 |
+-----------------------+
1 row in set (0.00 sec)

mysql> select hex(encode("1234","1234"));
+----------------------------+
| hex(encode("1234","1234")) |
+----------------------------+
| 25CD63DF                   |
+----------------------------+
1 row in set (0.00 sec)

mysql> select decode(encode("1234","1234"),"1234");
+--------------------------------------+
| decode(encode("1234","1234"),"1234") |
+--------------------------------------+
| 1234                                 |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> select decode(unhex("25CD63DF"),"1234");
+----------------------------------+
| decode(unhex("25CD63DF"),"1234") |
+----------------------------------+
| 1234                             |
+----------------------------------+
1 row in set (0.00 sec)

mysql>