简体   繁体   English

如何在mysql表中插入中文字符?

[英]How to insert chinese character in mysql table?

I want to save data in Chinese language in mysql table. 我想在mysql表中用中文保存数据。

Can anyone tell me what settings I have to do for it in mysql and PHP. 任何人都可以告诉我在mysql和PHP中我必须做些什么设置。

My table will save data in both English and Chinese some column English other Chinese . 我的表格将保存英文和中文的数据一些英文其他中文。 Is it possible with single table. 单表是否可行。

Any help will be appreciated. 任何帮助将不胜感激。

Use UTF-8 when you create table 创建表时使用UTF-8

create table xxx ()CHARACTER SET = utf8;

Use UTF-8 when you insert to table 插入表时使用UTF-8

set names utf8; insert into xxx (xx,x);

Set the character set to UTF-8, in mysql. 在mysql中将字符集设置为UTF-8。

Check this for reference 检查这个以供参考

http://confluence.jetbrains.net/display/TCD/Configuring+UTF8+Character+Set+for+MySQL http://dev.mysql.com/doc/refman/5.0/en/charset-mysql.html http://confluence.jetbrains.net/display/TCD/Configuring+UTF8+Character+Set+for+MySQL http://dev.mysql.com/doc/refman/5.0/en/charset-mysql.html

It works perfectly all right, but you have to set the character set and collation of the table BEFORE you insert any chinese characters. 它可以完美地工作,但您必须在插入任何中文字符之前设置表的字符集和排序规则。

mysql> create table foo (v varchar(10)) CHARACTER SET utf8 COLLATE utf8_general_ci; 

Query OK, 0 rows affected (0.00 sec) 

mysql> insert into foo values('雷蒙德'); Query OK, 1 row affected (0.00 sec) 

mysql> select * from foo; 

+-----------------------+ 

| v | 

+-----------------------+ 

| 雷蒙德 | 

+-----------------------+ 

1 row in set (0.00 sec)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM