{"id":4477,"date":"2019-06-16T21:17:57","date_gmt":"2019-06-16T13:17:57","guid":{"rendered":"https:\/\/ixyzero.com\/blog\/?p=4477"},"modified":"2019-06-16T21:17:57","modified_gmt":"2019-06-16T13:17:57","slug":"mysql%e5%b8%b8%e8%a7%81%e9%94%99%e8%af%af%e7%a0%81%e5%8f%8a%e5%85%b6%e8%a7%a3%e5%86%b3%e6%96%b9%e5%bc%8f%e6%95%b4%e7%90%86","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/4477.html","title":{"rendered":"MySQL\u5e38\u89c1\u9519\u8bef\u7801\u53ca\u5176\u89e3\u51b3\u65b9\u5f0f\u6574\u7406"},"content":{"rendered":"\n<p>=Start=<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7f18\u7531\uff1a<\/h4>\n\n\n\n<p>\u6574\u7406\u4e00\u4e0bMySQL\u5e38\u89c1\u7684\u9519\u8bef\u7801\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\uff0c\u65b9\u4fbf\u4ee5\u540e\u8981\u7528\u7684\u65f6\u5019\u53c2\u8003\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6b63\u6587\uff1a<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\"><strong>1\u3001MySQL\u4e2d\u7684utf8\u7f16\u7801\u548cutf8mb4\u7f16\u7801<\/strong><\/h6>\n\n\n\n<p>\u5148\u8bf4\u7ed3\u8bba\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>MySQL\u7684\u201cutf8\u201d\u5b9e\u9645\u4e0a\u4e0d\u662f\u771f\u6b63\u7684\u201cUTF-8\u201d\u3002<\/strong><\/li><li>MySQL\u7684\u201cutf8\u201d\u662f\u4e00\u79cd\u201c\u4e13\u5c5e\u7684\u7f16\u7801\u201d\uff0c\u5b83\u80fd\u591f\u7f16\u7801\u7684Unicode\u5b57\u7b26\u5e76\u4e0d\u591a\uff08\u53ea\u652f\u6301\u6700\u957f\u4e09\u4e2a\u5b57\u8282\u7684 UTF-8\u5b57\u7b26\uff0c\u4e5f\u5c31\u662f Unicode \u4e2d\u7684\u57fa\u672c\u591a\u6587\u672c\u5e73\u9762(BMP)\uff09\u3002<\/li><li><strong>MySQL\u7684\u201cutf8mb4\u201d\u624d\u662f\u771f\u6b63\u7684\u201cUTF-8\u201d\u3002<\/strong><\/li><\/ul>\n\n\n\n<p>MySQL\u57285.5.3\u4e4b\u540e\u589e\u52a0\u4e86utf8mb4\u7684\u7f16\u7801\uff0cmb4\u5c31\u662fmost bytes 4\u7684\u610f\u601d\uff0c\u4e13\u95e8\u7528\u6765\u517c\u5bb9\u56db\u5b57\u8282\u7684unicode\u3002\u597d\u5728utf8mb4\u662futf8\u7684\u8d85\u96c6\uff0c\u9664\u4e86\u5c06\u7f16\u7801\u6539\u4e3autf8mb4\u5916\u4e0d\u9700\u8981\u505a\u5176\u4ed6\u8f6c\u6362\u3002\u5f53\u7136\uff0c\u4e3a\u4e86\u8282\u7701\u7a7a\u95f4\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u4f7f\u7528utf8\u4e5f\u5c31\u591f\u4e86\uff08\u4f46\u4e0d\u652f\u6301&nbsp;Emoji \u8868\u60c5\uff09\u3002<\/p>\n\n\n\n<h6 class=\"wp-block-heading\"><strong>2\u3001Mysql Error 1366: Incorrect string value<\/strong>: &#8216;\\xF0\\x9F\\x90\\xA0&#8217; for column &#8216;xxx&#8217; at row 1<\/h6>\n\n\n\n<p><strong>\u8fd9\u901a\u5e38\u610f\u5473\u7740\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u5b57\u7b26\u96c6\u8bbe\u7f6e\u4e0d\u4e00\u81f4\u3002<\/strong><\/p>\n\n\n\n<p>\u73b0\u5728\u7684\u4e00\u4e9b\u804a\u5929\u8bb0\u5f55\u4e2d\u65f6\u4e0d\u65f6\u4f1a\u51fa\u73b0\u4e00\u4e9bEmoji\u8868\u60c5\uff0c\u6240\u4ee5\u5728\u5efaMySQL\u8868\u5b58\u50a8\u7684\u65f6\u5019\uff0c\u9700\u8981\u4f7f\u7528utf8mb4\u5b57\u7b26\u96c6\uff0c\u800c\u975e\u5e38\u89c4\u7684utf8\u5b57\u7b26\u96c6\u3002\u5373\uff0c\u5efa\u8bae\u666e\u901a\u8868\u4f7f\u7528utf8\uff0c\u5982\u679c\u8fd9\u4e2a\u8868\u9700\u8981\u652f\u6301emoji\u5c31\u4f7f\u7528utf8mb4\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\u9664\u4e86\u5728\u5efa\u5e93\u5efa\u8868\u7684\u65f6\u5019\u8981\u6ce8\u610f\u5b57\u7b26\u96c6\u7684\u8bbe\u7f6e\uff0c\u5728client\u8fde\u63a5\u7684\u65f6\u5019\uff0c\u4e5f\u8981\u6ce8\u610f\u5b57\u7b26\u96c6\u7684\u8bbe\u7f6e\u8981\u548cserver\u7aef\u4fdd\u6301\u4e00\u81f4\uff0c\u5426\u5219\u53ef\u80fd\u5c31\u4f1a\u51fa\u73b0\u8be5\u9519\u8bef\u3002<\/p>\n\n\n\n<h6 class=\"wp-block-heading\"><strong>3\u3001Mysql Error 1064: You have an error in your SQL syntax<\/strong>; check the manual that corresponds to your MySQL server version for the right syntax to use near<\/h6>\n\n\n\n<p>\u8fd9\u8868\u793a\u6709SQL\u8bed\u6cd5\u9519\u8bef\u3002\u5e38\u89c1\u539f\u56e0\u6709\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>\u884c\u5c3e\u8be5\u6709 \u9017\u53f7(,) \u6ca1\u6709\uff0c\u6700\u540e\u4e00\u884c\u4e0d\u8be5\u6709\u7684\u5374\u6709\u4e86\uff1b<\/strong><\/li><li>\u8868\u540d\u3001\u5217\u540d\u5efa\u8bae\u7528 \u53cd\u5f15\u53f7(`) \u5305\u88f9\u8d77\u6765\uff0c\u800c\u4e0d\u8981\u7528\u5355\u5f15\u53f7\/\u53cc\u5f15\u53f7\uff1b<\/li><li><strong>\u5b57\u7b26\u4e32\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26(\u6bd4\u5982\uff1a\u5355\u5f15\u53f7\/\u53cc\u5f15\u53f7)\u8981\u8bb0\u5f97\u8f6c\u4e49\u3002<\/strong><\/li><\/ul>\n\n\n\n<h6 class=\"wp-block-heading\"><strong>4\u3001Mysql Error 1264: Out of range value for column<\/strong><\/h6>\n\n\n\n<p><strong>\u8981\u63d2\u5165\u7684\u5185\u5bb9\u8d85\u8fc7\u4e86\u5b57\u6bb5\u80fd\u8868\u8fbe\u7684\u8303\u56f4\u3002<\/strong>\u6bd4\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8981\u63d2\u5165\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u4e3a 120 \uff0c\u4f46\u662f\u8be5\u5217\u7684\u7c7b\u578b\u4e3a VARCHAR(100) \uff1b<\/li><li>\u8981\u63d2\u5165\u4e00\u4e2a\u6574\u6570 3172978990 \u5230\u7c7b\u578b\u4e3a INT \u7684\u5b57\u6bb5\u4e2d\uff0c\u4f46\u662f\u56e0\u4e3a\u5b57\u6bb5\u7c7b\u578b\u7684\u9650\u5236\uff0c\u8be5\u5b57\u6bb5\u80fd\u8868\u793a\u7684\u6700\u5927\u6570\u503c\u4e3a 2147483647(2^31 &#8211; 1) \u63d2\u5165\u65f6\u5c31\u4f1a\u62a5\u9519\u3002<\/li><\/ul>\n\n\n\n<p>\u89e3\u51b3\u529e\u6cd5\u4e5f\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u5c06\u5bf9\u5e94\u7684\u5b57\u6bb5\u7c7b\u578b\u4fee\u6539\u6210\u6ee1\u8db3\u6761\u4ef6\u7684\u5c31\u597d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ \u5728\u4e00\u6761SQL\u8bed\u53e5\u4e2d\u5bf9\u591a\u4e2a\u5b57\u6bb5\u7c7b\u578b\u8fdb\u884c\u4fee\u6539\nALTER TABLE qqgroup MODIFY COLUMN group_id BIGINT,<br>MODIFY COLUMN sender_id BIGINT,<br>MODIFY COLUMN message_id BIGINT,<br>MODIFY COLUMN `sender_nickname` varchar(100),<br>MODIFY COLUMN `message` varchar(1500);<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/dba.stackexchange.com\/questions\/206478\/insert-gives-error-code-1366-incorrect-string-value-xf0-x9f-x98-x80-for-co\">INSERT gives Error Code: 1366. Incorrect string value: &#8216;\\xF0\\x9F\\x98\\x80&#8217; for column<\/a><\/li><li><strong><a href=\"https:\/\/stackoverflow.com\/questions\/10957238\/incorrect-string-value-when-trying-to-insert-utf-8-into-mysql-via-jdbc\">\u201cIncorrect string value\u201d when trying to insert UTF-8 into MySQL via JDBC?<\/a><\/strong><\/li><li><a href=\"http:\/\/ourmysql.com\/archives\/1402\">\u6e05\u5b98\u8c08mysql\u4e2dutf8\u548cutf8mb4\u533a\u522b<\/a><\/li><li><a href=\"https:\/\/www.eversql.com\/mysql-utf8-vs-utf8mb4-whats-the-difference-between-utf8-and-utf8mb4\/\">MySQL utf8 vs utf8mb4 \u2013 What\u2019s the difference between utf8 and utf8mb4?<\/a><\/li><li><a href=\"https:\/\/www.techug.com\/post\/in-mysql-never-use-utf8-use-utf8mb4.html\">\u8bd1 | \u6c38\u8fdc\u4e0d\u8981\u5728MySQL\u4e2d\u4f7f\u7528utf8\uff0c\u6539\u7528utf8mb4<\/a><br><a href=\"https:\/\/medium.com\/@adamhooper\/in-mysql-never-use-utf8-use-utf8mb4-11761243e434\">https:\/\/medium.com\/@adamhooper\/in-mysql-never-use-utf8-use-utf8mb4-11761243e434<\/a><\/li><li><a href=\"http:\/\/seanlook.com\/2016\/10\/23\/mysql-utf8mb4\/\">mysql\u4f7f\u7528utf8mb4\u7ecf\u9a8c\u5410\u8840\u603b\u7ed3<\/a><\/li><li><a href=\"https:\/\/my.oschina.net\/xsh1208\/blog\/1052781\">\u5168\u9762\u4e86\u89e3mysql\u4e2dutf8\u548cutf8mb4\u7684\u533a\u522b<\/a><\/li><li><strong><a href=\"https:\/\/chengfeng.site\/2018\/07\/18\/mysql%E4%B8%ADutf8%E4%B8%8Eutf8mb4\/\">MySQL\u4e2dutf8\u4e0eutf8mb4<\/a><\/strong><\/li><li><a href=\"https:\/\/www.crifan.com\/mysql_insert_error_1064_you_have_an_error_in_your_sql_syntax\/\">\u3010\u5df2\u89e3\u51b3\u3011mysql\u63d2\u5165\u51fa\u9519\uff1aError 1064 You have an error in your SQL syntax<\/a><\/li><li><a href=\"https:\/\/stackoverflow.com\/questions\/887036\/how-to-escape-single-quotes-in-mysql\">How to escape single quotes in MySQL<\/a><\/li><li><a href=\"https:\/\/chartio.com\/learn\/sql-tips\/single-double-quote-and-backticks-in-mysql-queries\/\">Single Quote, Double Quote, and Backticks in MySQL Queries<\/a><\/li><li><strong>Mysql\u5e38\u89c1\u9519\u8bef\u7801\u8bb2\u89e3<\/strong><br><a href=\"https:\/\/segmentfault.com\/a\/1190000010996553\">https:\/\/segmentfault.com\/a\/1190000010996553<\/a><\/li><li><a href=\"https:\/\/stackoverflow.com\/questions\/14284494\/mysql-error-1264-out-of-range-value-for-column\">MySQL Error 1264: out of range value for column<\/a><\/li><li><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/out-of-range-and-overflow.html\">11.2.6 Out-of-Range and Overflow Handling<\/a><\/li><\/ul>\n\n\n\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u6574\u7406\u4e00\u4e0bMySQL\u5e38\u89c1\u7684\u9519\u8bef\u7801\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\uff0c\u65b9\u4fbf\u4ee5\u540e\u8981\u7528\u7684\u65f6\u5019\u53c2\u8003\u3002 \u6b63\u6587\uff1a \u53c2\u8003\u89e3\u7b54 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,23,12],"tags":[16,1433,1434,1435],"class_list":["post-4477","post","type-post","status-publish","format-standard","hentry","category-database","category-knowledgebase-2","category-tools","tag-mysql","tag-utf8","tag-utf8mb4","tag-1435"],"views":4656,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/4477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=4477"}],"version-history":[{"count":1,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/4477\/revisions"}],"predecessor-version":[{"id":4479,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/4477\/revisions\/4479"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=4477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=4477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=4477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}