Home  >  Article  >  Database  >  mysql默认编码的问题_MySQL

mysql默认编码的问题_MySQL

WBOY
WBOYOriginal
2016-06-01 13:42:361014browse

bitsCN.com
mysql默认编码的问题 在MySQL的Client建数据库:CREATE DATABASE bbs2007;USE bbs2007; 再建表:CREATE TABLE article (id INT PRIMARY KEY AUTO_INCREMENT,pid INT,rootid INT,title VARCHAR(255),cont TEXT,pdate DATETIME,isleaf INT #1-not leaf 0-leaf);     往表插数据:INSERT INTO article VALUES (NULL, 0, 1, '蚂蚁大战大象', '蚂蚁大战大象', NOW(), 1); 出现这个错误:MySQL插入中文时出现ERROR 1406 (22001): Data too long for column 'name' at row 1
解决办法是:
先使用命令set names gbk;再执行插入数据的SQL语句。原因是因为MySQL Client默认编码是Latin1,不支持中文, set names gbk;是把所有的字段设置成支持中文的编码。   摘自 heirenheiren的专栏 bitsCN.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn