{"id":93399,"date":"2020-04-05T01:32:31","date_gmt":"2020-04-04T17:32:31","guid":{"rendered":"http:\/\/4563.org\/?p=93399"},"modified":"2020-04-05T01:32:31","modified_gmt":"2020-04-04T17:32:31","slug":"%e5%88%86%e4%ba%ab%e4%b8%80%e4%b8%aa%e4%bb%8a%e5%a4%a9%e8%b8%a9%e5%be%97-mysql-%e7%bc%96%e7%a0%81%e5%9d%91","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=93399","title":{"rendered":"\u5206\u4eab\u4e00\u4e2a\u4eca\u5929\u8e29\u5f97 MySQL \u7f16\u7801\u5751"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5206\u4eab\u4e00\u4e2a\u4eca\u5929\u8e29\u5f97 MySQL \u7f16\u7801\u5751               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : whoami9894 <\/span>  <span><i><\/i> 18<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6709\u8fd9\u6837\u4e09\u5f20\u8868\uff0c\u4e09\u5f20\u8868\u4e3b\u952e\u90fd\u662f stu_num:<\/p>\n<ul>\n<li>auth (utf8mb4)\uff0c\u8ba4\u8bc1<\/li>\n<li>info (utf8mb4)\uff0c\u7528\u6237 basic info<\/li>\n<li>apply (utf8)\uff0c\u7528\u6237\u63d0\u4ea4\u7533\u8bf7<\/li>\n<\/ul>\n<p>\u8d77\u56e0\u662f\u53d1\u73b0\u8fd4\u56de apply \u8bb0\u5f55\u7684 JSON \u63a5\u53e3\u6709\u4e00\u4e2a\u7528\u6237\u5b57\u6bb5\u91cd\u590d\u4e86\uff0c\u8be5\u63a5\u53e3\u67e5\u8be2\u662f\uff1a<\/p>\n<pre><code>SELECT ... FROM apply a LEFT JOIN info i ON a.stu_num=i.stu_num <\/code><\/pre>\n<p>\u6392\u67e5\u540e\u53d1\u73b0 apply \u4e2d\u591a\u4e86\u4e00\u4e2a\u5168\u89d2<code>stu_num<\/code>\u7684\u8bb0\u5f55\uff0c<code>\uff11\uff11\uff11\uff11<\/code>\uff0cunicode <code>uFF11<\/code>\u3002\u4f46\u63d2\u5165 apply \u8868\u7684<code>stu_num<\/code>\u662f\u4ece session \u4e2d\u53d6\u7684\uff0csession \u662f\u5728\u767b\u5f55\u65f6\u8bbe\u7f6e\u7684\uff0c\u767b\u5f55\u9a8c\u8bc1\u903b\u8f91\uff1a<\/p>\n<pre><code>uname, pwd = request.post_form.get(); if (hash(pwd) == sql_exec('SELECT pwd FROM auth WHERE uname=?', uname))     session.set('uname', uname); <\/code><\/pre>\n<p>\u6700\u540e\u7ed3\u5408 log \u53d1\u73b0\u662f\u7528\u6237\u767b\u5f55\u65f6\u63d0\u4ea4\u4e86\u5168\u89d2\u7684\u6570\u5b57 id\uff0c\u800c\u7531\u4e8e<code>auth<\/code>\u8868\u7684\u5b57\u7b26\u96c6\uff0c<code>uname='\uff11\uff11\uff11\uff11'<\/code>\u65f6\u5c06<code>uname='1111'<\/code>\u7684\u8bb0\u5f55 SELECT \u51fa\u6765\u4e86\uff0c\u7136\u540e\u5c06\u5168\u89d2\u5b57\u7b26\u8bbe\u7f6e\u8fdb\u4e86 session \u91cc\uff0c\u5728 apply \u65f6\u88ab\u63d2\u5165\u4e86 apply \u4e2d<\/p>\n<p>\u5176\u5b9e\u633a\u597d\u5947\u7528\u6237\u7528\u7684\u4ec0\u4e48\u6d4f\u89c8\u5668 or \u8f93\u5165\u6cd5\u4f1a\u8f93\u5165\u5168\u89d2\u7684\u6570\u5b57<\/p>\n<p>\u63d2\u66f2<\/p>\n<p>debug \u8fc7\u7a0b\u4e2d\u53d1\u73b0\u4e86\u4e00\u4e9b\u4ee5\u524d\u6ca1\u6709\u6ce8\u610f\u5230\u7684\uff0c\u5173\u4e8e MySQL COLLATE<\/p>\n<p>\u6392\u67e5\u65f6\u6267\u884c<code>SELECT count(*) FROM apply WHERE stu_num='1111';<\/code>\u53ea\u8fd4\u56de\u4e86\u4e00\u6761\u8bb0\u5f55<\/p>\n<p>\u800c bug \u6210\u56e0\u662f<code>SELECT pwd FROM auth WHERE uname='\uff11\uff11\uff11\uff11'<\/code>\u8fd4\u56de\u4e86<code>stu_num=1111<\/code>\u7684\u8bb0\u5f55\u3002\u6d4b\u8bd5\u540e\u662f\u56e0\u4e3a\u5b57\u7b26\u96c6 COLLATE \u5bfc\u81f4\u7684\uff0cutf8mb4 \u5b58\u5728\u5c06\u5168\u89d2\u8f6c\u6362\u4e3a\u534a\u89d2\u7684\u6027\u8d28\uff0c\u800c utf8 \u7684<code>utf8_general_ci<\/code>\u5374\u6ca1\u6709\u8fd9\u79cd\u6027\u8d28<\/p>\n<p>\u4e14\u67e5\u8be2 apply \u7684\u63a5\u53e3\u4e4b\u6240\u4ee5 SELECT \u51fa\u4e86\u4e24\u6761\u8bb0\u5f55\uff0c\u662f\u56e0\u4e3a JOIN \u64cd\u4f5c ON \u5224\u65ad\u7684\u4e24\u5f20\u8868\u4e2d\u6709\u4e00\u5f20\u8868\u7684\u5b57\u7b26\u96c6\u6709\u8f6c\u6362\u5168\u89d2\u7684\u6027\u8d28\uff0c\u4fee\u6539 info \u8868\u5b57\u7b26\u96c6\u4e3a utf8 \u540e\u518d join apply \u8868\u5219\u53ea\u80fd SELECT \u51fa<code>1111<\/code>\u4e00\u6761\u8bb0\u5f55\u4e86<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1122630\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Vegetable <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4ec0\u4e48\u8f93\u5165\u6cd5\u90fd\u6709\u53ef\u80fd<br \/>\u4e0d\u5c0f\u5fc3\u6309\u5230\u5feb\u6377\u952e\u592a\u6b63\u5e38\u4e86\uff11\uff12\uff13\uff14\uff15                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1122631\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Vegetable <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5fae\u8f6f\uff53\uff48\uff49\uff46\uff54\uff0b\uff53\uff50\uff41\uff43\uff45                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1122632\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : whoami9894 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Vegetable <br \/>\u786e\u5b9e\u3002\u6211\u539f\u6765\u4e00\u76f4\u4ee5\u4e3a\u8f93\u5165\u6cd5\u53ea\u6709\u7279\u6b8a\u5b57\u7b26\u4f1a\u8f93\u5165\u5168\u89d2                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5206\u4eab\u4e00\u4e2a\u4eca\u5929\u8e29\u5f97 MySQL \u7f16\u7801&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/93399"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=93399"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/93399\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=93399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=93399"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=93399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}