Home  >  Article  >  Database  >  mac mysql汉字乱码问题解决_MySQL

mac mysql汉字乱码问题解决_MySQL

WBOY
WBOYOriginal
2016-06-01 13:34:101123browse

bitsCN.com

mac mysql汉字乱码问题解决

 

 在创建数据库和创建表时最好都指定字符编码

例:create database db_name DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;//创建数据库

 

create table order_list(

id int unsigned not null AUTO_INCREMENT,

O_name VARCHAR(40) not null,

O_desc VARCHAR(600) DEFAULT ' ',

O_category VARCHAR(50) not null,

O_style VARCHAR(20) DEFAULT ' ',

O_state enum('1','0') not null,

O_unitprice double not null,

O_icon VARCHAR(20) not null,

primary key (id)

)ENGINE=MYISAM AUTO_INCREMENT=1 DEFAULT CHARACTERSET=utf8;

//创建表

insert into order_list values(null,'哈哈','asdsadas','cai','zhongcan','1',12.5,'xiao.png');

/插入

如果没有上边两步的指定编码,则第三步插入时会提示第二个元素错误,因为不指定默认是latin编码,不支持汉字插入

 

另外要支持客服端的汉字输出,像与php绑定输出汉字

这需要修改/usr/local/mysql/my.cnf

修改内容为

 

其中

[client]

default-character-set = utf8

character-set-server = utf8

是添加的。

到这里就可以输出汉字了。
 

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