mysql修改表、字段、库的字符集
修改数据库字符集:
|
<span style="font-weight: bold; color: #993333;">ALTER</span> <span style="font-weight: bold; color: #993333;">DATABASE</span> db_name <span style="font-weight: bold; color: #993333;">DEFAULT</span> <span style="font-weight: bold; color: #993333;">CHARACTER</span> <span style="font-weight: bold; color: #993333;">SET</span> character_name <span style="color: #66cc66;">[</span><span style="font-weight: bold; color: #993333;">COLLATE</span> <span style="color: #66cc66;">...</span><span style="color: #66cc66;">]</span>; |
|
把表默认的字符集和所有字符列(CHAR,VARCHAR,TEXT)改为新的字符集:
|
<span style="font-weight: bold; color: #993333;">ALTER</span> <span style="font-weight: bold; color: #993333;">TABLE</span> tbl_name <span style="font-weight: bold; color: #993333;">CONVERT</span> <span style="font-weight: bold; color: #993333;">TO</span> <span style="font-weight: bold; color: #993333;">CHARACTER</span> <span style="font-weight: bold; color: #993333;">SET</span> character_name <span style="color: #66cc66;">[</span><span style="font-weight: bold; color: #993333;">COLLATE</span> <span style="color: #66cc66;">...</span><span style="color: #66cc66;">]</span> 如:<span style="font-weight: bold; color: #993333;">ALTER</span> <span style="font-weight: bold; color: #993333;">TABLE</span> logtest <span style="font-weight: bold; color: #993333;">CONVERT</span> <span style="font-weight: bold; color: #993333;">TO</span> <span style="font-weight: bold; color: #993333;">CHARACTER</span> <span style="font-weight: bold; color: #993333;">SET</span> utf8 <span style="font-weight: bold; color: #993333;">COLLATE</span> utf8_general_ci; |
|
只是修改表的默认字符集:
|
<span style="font-weight: bold; color: #993333;">ALTER</span> <span style="font-weight: bold; color: #993333;">TABLE</span> tbl_name <span style="font-weight: bold; color: #993333;">DEFAULT</span> <span style="font-weight: bold; color: #993333;">CHARACTER</span> <span style="font-weight: bold; color: #993333;">SET</span> character_name <span style="color: #66cc66;">[</span><span style="font-weight: bold; color: #993333;">COLLATE</span><span style="color: #66cc66;">...</span><span style="color: #66cc66;">]</span>; 如:<span style="font-weight: bold; color: #993333;">ALTER</span> <span style="font-weight: bold; color: #993333;">TABLE</span> logtest <span style="font-weight: bold; color: #993333;">DEFAULT</span> <span style="font-weight: bold; color: #993333;">CHARACTER</span> <span style="font-weight: bold; color: #993333;">SET</span> utf8 <span style="font-weight: bold; color: #993333;">COLLATE</span> utf8_general_ci; |
|
修改字段的字符集:
|
<span style="font-weight: bold; color: #993333;">ALTER</span> <span style="font-weight: bold; color: #993333;">TABLE</span> tbl_name <span style="font-weight: bold; color: #993333;">CHANGE</span> c_name c_name <span style="font-weight: bold; color: #993333;">CHARACTER</span> <span style="font-weight: bold; color: #993333;">SET</span> character_name <span style="color: #66cc66;">[</span><span style="font-weight: bold; color: #993333;">COLLATE</span> <span style="color: #66cc66;">...</span><span style="color: #66cc66;">]</span>; 如:<span style="font-weight: bold; color: #993333;">ALTER</span> <span style="font-weight: bold; color: #993333;">TABLE</span> logtest <span style="font-weight: bold; color: #993333;">CHANGE</span> title title <span style="font-weight: bold; color: #993333;">VARCHAR</span><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">)</span> <span style="font-weight: bold; color: #993333;">CHARACTER</span> <span style="font-weight: bold; color: #993333;">SET</span> utf8 <span style="font-weight: bold; color: #993333;">COLLATE</span> utf8_general_ci; |
|
查看数据库编码:
|
<span style="font-weight: bold; color: #993333;">SHOW</span> <span style="font-weight: bold; color: #993333;">CREATE</span> <span style="font-weight: bold; color: #993333;">DATABASE</span> db_name; |
|
查看表编码:
|
<span style="font-weight: bold; color: #993333;">SHOW</span> <span style="font-weight: bold; color: #993333;">CREATE</span> <span style="font-weight: bold; color: #993333;">TABLE</span> tbl_name; |
|
查看字段编码:
|
<span style="font-weight: bold; color: #993333;">SHOW</span> <span style="font-weight: bold; color: #993333;">FULL</span> <span style="font-weight: bold; color: #993333;">COLUMNS</span> <span style="font-weight: bold; color: #993333;">FROM</span> tbl_name; |
|
来源:http://www.diannaowa.com/index.php/archives/233
from:http://fatkun.com/2011/05/mysql-alter-charset.html