今天,使用mysql workbench 給一張表添加了一列varchar類型的列。在插入中文數據時出現
這是編碼問題,只要將表的類型修改爲utf-8就ok了。
alter table 數據庫名.表名 convert to character set utf8;
執行完這條語句之後就可以插入中文數據啦。
如果多張表存在這個問題可以直接修改數據庫的編碼類型
alter database 數據名 character set utf8;
如果想在創建數據庫時就解決這個問題可以在建表時加
ENGINE=InnoDB DEFAULT CHARSET=utf8
例如:
create table newsBody(
newId int not null auto_increment,
article text not null,
bimage varchar(100),
primary key(newId),
foreign key(newId) references new(newId)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;