1. 程式人生 > >mysql更改表與欄位的編碼方式

mysql更改表與欄位的編碼方式

建立表時使用show create table student檢視發現編碼預設為latin1
這裡寫圖片描述

接下來使用alter table student default character set utf8;更改了資料表的編碼方式。
這裡寫圖片描述
發現表的編碼已經改為utf8,但是表中欄位還是latin1,對於性別欄位仍寫入漢字仍報錯。
接下來更改欄位的編碼方式

alter table student convert to character set utf8;

這樣應該就可以了吧,但是發現又出現了小錯誤。
這裡寫圖片描述

check the manual that corresponds to your MySQL server version
for the right syntax to use near 'utf8' at line 1

查閱相關資料,發現問題出在這裡
這裡寫圖片描述
單次插入的資料不能用兩行分開???,修改如下
這裡寫圖片描述
竟然就可以了。。。
參考1
參考2