MySql 表、字段、库的字符集修改及查看方法

Author Avatar
doubledna 2017 年 03 月 02 日

<div class="title"></div>
<div class="art_desc mt10">
<div id="art_demo"> 这篇文章主要介绍了 MySql 表、字段、库的字符集修改及查看方法, 本文分别给们它的修改及查看语句, 需要的朋友可以参考下 </div>
</div>
<div class="lbd clearfix"></div>
<div id="content">

修改数据库字符集:

<div class="codetitle"></div>
<div id="code87812" class="codebody">ALTER DATABASE db_name DEFAULT CHARACTER SET character_name [COLLATE ...];</div>
把表默认的字符集和所有字符列(CHAR,VARCHAR,TEXT)改为新的字符集:
<div class="codetitle"></div>
<div id="code79526" class="codebody">ALTER TABLE tbl_name CONVERT TO CHARACTER SET character_name [COLLATE ...]</div>
如:ALTER TABLE logtest CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; 只是修改表的默认字符集:
<div class="codetitle"></div>
<div id="code57500" class="codebody">ALTER TABLE tbl_name DEFAULT CHARACTER SET character_name [COLLATE...];</div>
如:ALTER TABLE logtest DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 修改字段的字符集:
<div class="codetitle"></div>
<div id="code97021" class="codebody">ALTER TABLE tbl_name CHANGE c_name c_name CHARACTER SET character_name [COLLATE ...];</div>
如:ALTER TABLE logtest CHANGE title title VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci; 查看数据库编码:
<div class="codetitle"></div>
<div id="code78458" class="codebody">SHOW CREATE DATABASE db_name;</div>
查看表编码:
<div class="codetitle"></div>
<div id="code60704" class="codebody">SHOW CREATE TABLE tbl_name;</div>
查看字段编码:
<div class="codetitle"></div>
<div id="code87407" class="codebody">SHOW FULL COLUMNS FROM tbl_name;</div>
</div>