{"id":5457,"date":"2024-11-14T12:46:39","date_gmt":"2024-11-14T04:46:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5457\/"},"modified":"2024-11-14T12:46:39","modified_gmt":"2024-11-14T04:46:39","slug":"%e6%80%8e%e4%b9%88%e6%9f%a5%e7%9c%8bmysql%e7%9a%84%e7%bc%96%e7%a0%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5457\/","title":{"rendered":"\u600e\u4e48\u67e5\u770bmysql\u7684\u7f16\u7801"},"content":{"rendered":"<blockquote><p>\n  \u67e5\u770b mysql \u7f16\u7801\u7684\u65b9\u6cd5\uff1a\u67e5\u8be2\u6570\u636e\u5e93\u6216\u8868\uff1a\u4f7f\u7528 show create database \u6216 show create table \u8bed\u53e5\uff0c\u5728 default character set= \u6216 character set= \u884c\u4e2d\u67e5\u770b\u7f16\u7801\u3002\u901a\u8fc7\u4fe1\u606f\u6a21\u5f0f\uff1a\u4f7f\u7528 select \u8bed\u53e5\u4ece information_schema.schemata \u6216 information_schema.tables \u8868\u4e2d\u67e5\u8be2 default_character_set_name \u6216 character_set_name \u5217\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052814512626910.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48\u67e5\u770bmysql\u7684\u7f16\u7801\u63d2\u56fe\" alt=\"\u600e\u4e48\u67e5\u770bmysql\u7684\u7f16\u7801\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u67e5\u770b MySQL \u7684\u7f16\u7801<\/strong><\/p>\n<p>\u67e5\u770b MySQL \u6570\u636e\u5e93\u6216\u8868\u7684\u7f16\u7801\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u67e5\u8be2\u6570\u636e\u5e93\u6216\u8868<\/strong><\/p>\n<pre>SHOW CREATE DATABASE database_name;\nSHOW CREATE TABLE table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd4\u56de\u7ed3\u679c\u4e2d\u5c06\u5305\u542b DEFAULT CHARACTER SET= \u6216 CHARACTER SET= \u884c\uff0c\u5176\u4e2d\u6307\u5b9a\u4e86\u7f16\u7801\u3002<\/p>\n<p><strong>2. \u901a\u8fc7\u4fe1\u606f\u6a21\u5f0f<\/strong><\/p>\n<pre>SELECT * FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'database_name';\nSELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'database_name' AND TABLE_NAME = 'table_name';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd4\u56de\u7ed3\u679c\u4e2d\u5c06\u5305\u542b DEFAULT_CHARACTER_SET_NAME \u6216 CHARACTER_SET_NAME \u5217\uff0c\u5176\u4e2d\u6307\u5b9a\u4e86\u7f16\u7801\u3002<\/p>\n<p><strong>3. \u76f4\u63a5\u8fde\u63a5\u5230\u6570\u636e\u5e93<\/strong><\/p>\n<pre>SHOW VARIABLES LIKE '%character_set%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd4\u56de\u7ed3\u679c\u5c06\u5305\u542b character_set_database, character_set_connection, character_set_results, character_set_server \u7b49\u53d8\u91cf\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u6570\u636e\u5e93\u3001\u8fde\u63a5\u3001\u7ed3\u679c\u548c\u670d\u52a1\u5668\u7684\u7f16\u7801\u4fe1\u606f\u3002<\/p>\n<p><strong>4. \u4f7f\u7528 MySQL \u547d\u4ee4\u884c\u5ba2\u6237\u7aef<\/strong><\/p>\n<p>\u5728 MySQL \u547d\u4ee4\u884c\u5ba2\u6237\u7aef\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u7f16\u7801\uff1a<\/p>\n<pre>s<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd4\u56de\u7ed3\u679c\u4e2d\u5c06\u5305\u542b Character set: \u884c\uff0c\u5176\u4e2d\u6307\u5b9a\u4e86\u7f16\u7801\u3002<\/p>\n<p><strong>5. \u4f7f\u7528 JDBC \u9a71\u52a8\u7a0b\u5e8f<\/strong><\/p>\n<p>\u4f7f\u7528 JDBC \u9a71\u52a8\u7a0b\u5e8f\u8fde\u63a5\u5230\u6570\u636e\u5e93\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u67e5\u770b\u7f16\u7801\uff1a<\/p>\n<pre>Connection conn = DriverManager.getConnection(url, username, password);\nDatabaseMetaData meta = conn.getMetaData();\nString encoding = meta.getDatabaseProductName();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u5982\u4f55\u4f7f\u7528 SQL \u67e5\u8be2\u67e5\u770b MySQL \u8868\u7684\u7f16\u7801\uff1a<\/p>\n<pre>SHOW CREATE TABLE employees;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd4\u56de\u7ed3\u679c\uff1a<\/p>\n<pre>CREATE TABLE `employees` (\n  `id` int(11) NOT NULL AUTO_INCREMENT,\n  `name` varchar(255) DEFAULT NULL,\n  `email` varchar(255) DEFAULT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8be5\u793a\u4f8b\u4e2d\uff0c\u8868\u7684\u7f16\u7801\u4e3a latin1\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u67e5\u770b\u7684\u7f16\u7801\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u67e5\u770b mysql \u7f16\u7801\u7684\u65b9\u6cd5\uff1a\u67e5\u8be2\u6570\u636e\u5e93\u6216\u8868\uff1a\u4f7f\u7528 show create database \u6216 show create table \u8bed\u53e5\uff0c\u5728 default character set= \u6216 character set= \u884c\u4e2d\u67e5\u770b\u7f16\u7801\u3002\u901a\u8fc7\u4fe1\u606f\u6a21\u5f0f\uff1a\u4f7f\u7528 select \u8bed\u53e5\u4ece information_schema.schemata \u6216 information_schema.tables \u8868\u4e2d\u67e5\u8be2 default_character_set_name \u6216 character_set_name \u5217 \u5982\u4f55\u67e5\u770b MySQL \u7684\u7f16\u7801 \u67e5\u770b MySQL \u6570\u636e\u5e93\u6216\u8868\u7684\u7f16\u7801\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a 1. \u67e5\u8be2\u6570\u636e\u5e93\u6216\u8868 SHOW CREATE DATABASE database_name; SHOW CREATE TABLE table_name; \u767b\u5f55\u540e\u590d\u5236 \u8fd4\u56de\u7ed3\u679c\u4e2d\u5c06\u5305\u542b DEFAULT CHARACTER SET= \u6216 CHARACTER SET= \u884c\uff0c\u5176\u4e2d\u6307\u5b9a\u4e86\u7f16\u7801\u3002 2. \u901a\u8fc7\u4fe1\u606f\u6a21\u5f0f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5457","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5457"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5457\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}