MySQL表、欄位、庫的字符集修改方法介紹

chenfeng發表於2017-03-21
修改資料庫字符集:

ALTER DATABASE db_name DEFAULT CHARACTER SET character_name [COLLATE ...];   
把表預設的字符集和所有字元列(CHAR,VARCHAR,TEXT)改為新的字符集:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET character_name [COLLATE ...]  
如:ALTER TABLE logtest CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; 

只是修改表的預設字符集:

ALTER TABLE tbl_name DEFAULT CHARACTER SET character_name [COLLATE...];  
如:ALTER TABLE logtest DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 


修改欄位的字符集:

ALTER TABLE tbl_name CHANGE c_name c_name CHARACTER SET character_name [COLLATE ...];  
如:ALTER TABLE logtest CHANGE title title VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci; 


檢視資料庫編碼:
SHOW CREATE DATABASE db_name; 
  
檢視錶編碼:
SHOW CREATE TABLE tbl_name;   

檢視欄位編碼:
SHOW FULL COLUMNS FROM tbl_name;   

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2135764/,如需轉載,請註明出處,否則將追究法律責任。

相關文章