{"id":77628,"date":"2024-10-16T10:58:17","date_gmt":"2024-10-16T02:58:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/77628\/"},"modified":"2024-10-16T10:58:17","modified_gmt":"2024-10-16T02:58:17","slug":"mysql%e6%80%8e%e9%ba%bc%e5%ad%98%e6%96%87%e6%9c%ac%e4%b8%8d%e4%ba%82%e7%a2%bc%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/77628\/","title":{"rendered":"MySQL\u600e\u9ebc\u5b58\u6587\u672c\u4e0d\u4e82\u78bc\uff1f"},"content":{"rendered":"<h1 id=\"mysql%e6%80%8e%e9%ba%bc%e5%ad%98%e6%96%87%e6%9c%ac%e4%b8%8d%e4%ba%82%e7%a2%bc%ef%bc%9f-GgxZgqwLsQ\">MySQL\u600e\u9ebc\u5b58\u6587\u672c\u4e0d\u4e82\u78bc\uff1f<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u666e\u904d\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u7136\u800c\uff0c\u7576\u6d89\u53ca\u5230\u5b58\u5132\u6587\u672c\u6578\u64da\u6642\uff0c\u7279\u5225\u662f\u591a\u8a9e\u8a00\u6587\u672c\uff0c\u4e82\u78bc\u554f\u984c\u7d93\u5e38\u51fa\u73fe\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728MySQL\u4e2d\u6b63\u78ba\u5b58\u5132\u6587\u672c\u4ee5\u907f\u514d\u4e82\u78bc\u554f\u984c\u3002<\/p>\n<h2 id=\"%e4%ba%82%e7%a2%bc%e7%9a%84%e5%8e%9f%e5%9b%a0-GgxZgqwLsQ\">\u4e82\u78bc\u7684\u539f\u56e0<\/h2>\n<p>\u4e82\u78bc\u901a\u5e38\u662f\u7531\u65bc\u5b57\u7b26\u7de8\u78bc\u4e0d\u5339\u914d\u6240\u5f15\u8d77\u7684\u3002\u7576\u6578\u64da\u4ee5\u4e00\u7a2e\u7de8\u78bc\u683c\u5f0f\u5b58\u5132\uff0c\u4f46\u5728\u6aa2\u7d22\u6216\u986f\u793a\u6642\u4f7f\u7528\u4e86\u53e6\u4e00\u7a2e\u7de8\u78bc\u683c\u5f0f\uff0c\u5c31\u6703\u51fa\u73fe\u4e82\u78bc\u3002\u4f8b\u5982\uff0c\u5c07UTF-8\u7de8\u78bc\u7684\u6587\u672c\u4ee5Latin1\u7de8\u78bc\u5b58\u5132\uff0c\u6703\u5c0e\u81f4\u5b57\u7b26\u7121\u6cd5\u6b63\u78ba\u986f\u793a\u3002<\/p>\n<h2 id=\"%e9%81%b8%e6%93%87%e6%ad%a3%e7%a2%ba%e7%9a%84%e5%ad%97%e7%ac%a6%e9%9b%86-GgxZgqwLsQ\">\u9078\u64c7\u6b63\u78ba\u7684\u5b57\u7b26\u96c6<\/h2>\n<p>\u70ba\u4e86\u907f\u514d\u4e82\u78bc\uff0c\u9996\u5148\u9700\u8981\u9078\u64c7\u6b63\u78ba\u7684\u5b57\u7b26\u96c6\u3002MySQL\u652f\u6301\u591a\u7a2e\u5b57\u7b26\u96c6\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662fUTF-8\u3002UTF-8\u80fd\u5920\u652f\u6301\u591a\u7a2e\u8a9e\u8a00\u7684\u5b57\u7b26\uff0c\u9069\u5408\u5b58\u5132\u570b\u969b\u5316\u6587\u672c\u3002<\/p>\n<h3 id=\"%e8%a8%ad%e7%bd%ae%e6%95%b8%e6%93%9a%e5%ba%ab%e5%ad%97%e7%ac%a6%e9%9b%86-GgxZgqwLsQ\">\u8a2d\u7f6e\u6578\u64da\u5eab\u5b57\u7b26\u96c6<\/h3>\n<p>\u5728\u5275\u5efa\u6578\u64da\u5eab\u6642\uff0c\u53ef\u4ee5\u6307\u5b9a\u5b57\u7b26\u96c6\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>CREATE DATABASE my_database CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/code><\/pre>\n<p>\u9019\u88e1\u4f7f\u7528\u4e86utf8mb4\uff0c\u9019\u662fUTF-8\u7684\u4e00\u500b\u64f4\u5c55\uff0c\u80fd\u5920\u652f\u6301\u66f4\u591a\u7684Unicode\u5b57\u7b26\uff0c\u5305\u62ec\u8868\u60c5\u7b26\u865f\u3002<\/p>\n<h3 id=\"%e8%a8%ad%e7%bd%ae%e8%a1%a8%e5%92%8c%e5%88%97%e7%9a%84%e5%ad%97%e7%ac%a6%e9%9b%86-GgxZgqwLsQ\">\u8a2d\u7f6e\u8868\u548c\u5217\u7684\u5b57\u7b26\u96c6<\/h3>\n<p>\u5728\u5275\u5efa\u8868\u6642\uff0c\u4e5f\u53ef\u4ee5\u6307\u5b9a\u5b57\u7b26\u96c6\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>CREATE TABLE my_table (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    text_column VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci\n);<\/code><\/pre>\n<h2 id=\"%e9%80%a3%e6%8e%a5%e5%ad%97%e7%ac%a6%e9%9b%86%e8%a8%ad%e7%bd%ae-GgxZgqwLsQ\">\u9023\u63a5\u5b57\u7b26\u96c6\u8a2d\u7f6e<\/h2>\n<p>\u9664\u4e86\u8a2d\u7f6e\u6578\u64da\u5eab\u548c\u8868\u7684\u5b57\u7b26\u96c6\u5916\uff0c\u9084\u9700\u8981\u78ba\u4fdd\u5728\u9023\u63a5\u5230MySQL\u6642\u4f7f\u7528\u6b63\u78ba\u7684\u5b57\u7b26\u96c6\u3002\u53ef\u4ee5\u5728\u9023\u63a5\u5b57\u7b26\u4e32\u4e2d\u6307\u5b9a\u5b57\u7b26\u96c6\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code>mysqli_set_charset($connection, \"utf8mb4\");<\/code><\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u5728\u8207\u6578\u64da\u5eab\u4ea4\u4e92\u6642\uff0c\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\u8207\u6578\u64da\u5eab\u4e2d\u7684\u5b57\u7b26\u96c6\u4e00\u81f4\u3002<\/p>\n<h2 id=\"%e6%aa%a2%e6%9f%a5%e5%92%8c%e8%bd%89%e6%8f%9b%e5%ad%97%e7%ac%a6%e9%9b%86-GgxZgqwLsQ\">\u6aa2\u67e5\u548c\u8f49\u63db\u5b57\u7b26\u96c6<\/h2>\n<p>\u5982\u679c\u5df2\u7d93\u5b58\u5728\u7684\u6578\u64da\u51fa\u73fe\u4e82\u78bc\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\u8a9e\u53e5\u6aa2\u67e5\u5b57\u7b26\u96c6\uff1a<\/p>\n<pre><code>SHOW CREATE TABLE my_table;<\/code><\/pre>\n<p>\u5982\u679c\u767c\u73fe\u5b57\u7b26\u96c6\u4e0d\u6b63\u78ba\uff0c\u53ef\u4ee5\u4f7f\u7528ALTER TABLE\u8a9e\u53e5\u9032\u884c\u8f49\u63db\uff1a<\/p>\n<pre><code>ALTER TABLE my_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e5%92%8c%e9%a9%97%e8%ad%89-GgxZgqwLsQ\">\u6e2c\u8a66\u548c\u9a57\u8b49<\/h2>\n<p>\u5728\u5b8c\u6210\u4e0a\u8ff0\u8a2d\u7f6e\u5f8c\uff0c\u5efa\u8b70\u9032\u884c\u6e2c\u8a66\u4ee5\u78ba\u4fdd\u6587\u672c\u80fd\u5920\u6b63\u78ba\u5b58\u5132\u548c\u6aa2\u7d22\u3002\u53ef\u4ee5\u63d2\u5165\u4e00\u4e9b\u5305\u542b\u7279\u6b8a\u5b57\u7b26\u7684\u6587\u672c\uff0c\u7136\u5f8c\u6aa2\u7d22\u4e26\u986f\u793a\u9019\u4e9b\u6587\u672c\uff0c\u6aa2\u67e5\u662f\u5426\u51fa\u73fe\u4e82\u78bc\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-GgxZgqwLsQ\">\u7e3d\u7d50<\/h2>\n<p>\u5728MySQL\u4e2d\u5b58\u5132\u6587\u672c\u800c\u4e0d\u51fa\u73fe\u4e82\u78bc\u7684\u95dc\u9375\u5728\u65bc\u9078\u64c7\u6b63\u78ba\u7684\u5b57\u7b26\u96c6\u548c\u78ba\u4fdd\u5728\u6578\u64da\u5eab\u3001\u8868\u3001\u5217\u53ca\u9023\u63a5\u4e2d\u4f7f\u7528\u4e00\u81f4\u7684\u5b57\u7b26\u96c6\u3002\u901a\u904e\u6b63\u78ba\u7684\u8a2d\u7f6e\u548c\u6e2c\u8a66\uff0c\u53ef\u4ee5\u6709\u6548\u907f\u514d\u4e82\u78bc\u554f\u984c\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u53ef\u8b80\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u7ba1\u7406\u6578\u64da\u5eab\u548c\u61c9\u7528\u7a0b\u5e8f\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f <a href=\"https:\/\/server.hk\">\u96f2\u4f3a\u670d\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728MySQL\u4e2d\u6b63\u78ba\u5b58\u5132\u6587\u672c\u4ee5\u907f\u514d\u4e82\u78bc\u554f\u984c\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u53ef\u8b80\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-77628","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/77628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=77628"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/77628\/revisions"}],"predecessor-version":[{"id":77629,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/77628\/revisions\/77629"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=77628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=77628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=77628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}