mysql chinese character-set

第一种:初始化文件(my.cnf)中设置参数

mysql数据库默认的字符集是latin。所以需要在my.cnf中设置下。比如:

[[email protected] test]# more /etc/my.cnf

[mysqld]

default-character-set=utf8

然后连接进mysql,查看:

mysql> status

Server characterset: utf8
Db characterset: utf8
Client characterset: latin1
Conn. characterset: latin1
第二种:设置客户端的字符集

在连接mysql的时候,需要加上个参数,比如:

[[email protected] test]# mysql -uroot -p –default-character-set=utf8

mysql> status

Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
第三种:修改服务器的环境变量 LANG

[[email protected] test]# export LANG=en_US

然后再连接mysql,就可以输入中文了。
总结:

前两种方法主要是解决中文乱码的问题, 第三种方法是解决不能输入中文的方法。

debian下mysql的字符串修改为utf8(参考:rainysia的专栏)

一、进入mysql(mysql -uroot -p),查看当前数据库字符集(status;)

二、查看当前系统版本(lsb_release -a)

Mysql不能插入中文

三、#vim /etc/mysql/my.cnf 。(5.5以前系统)在【client】下面加入
default-character-set=utf8

在【mysqld】下面加入default-character-set=utf8

Notice:注意
如果修改后不能启动报错试试把default-character-set=utf8改为character_set_server=utf8,仅仅加入到mysqld下面的.client就不需要加了

四、#vim /etc/mysql/my.cnf 。(5.5以后系统)如下修改:

[client]
default-character-set=utf8

[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci

五、重启mysql(/etc/init.d/mysql stop /etc/init.d/mysql start)

六、修成成功,进入mysql查看字符集(mysql>show variables like ‘character_set_%’;)

时间: 2024-09-30 12:35:38

mysql chinese character-set的相关文章

IEF could not decode Chinese character in IE history well

My friend is working on some case, and she looks not in the mood. I ask her what's going on. She wants me to look at the screenshot as below. That's why she is upset...IEF could not decode Chinese character in IE history well, so the filenames in Chi

[Powershell] Convert Chinese character to pinying

Found a new job in Beijing, the company was using cloud stuff for infrastructure IT systems, like mail system, mobile messaging, IM. The company is going bigger and stronger, making more money, so the bosses decided update to AD/exchange/lync. It is

EnCase v7 could not recognize Chinese character folder names / file names on Linux Platform

Last week my friend brought me an evidence file duplicated from a Linux server, which distribution is CentOS 5.0 and the i18n is zh-tw. She wanna know whether there is any malware on this Linux server or not. OK. Let's get to work. I add this evidenc

csharp: Converting chinese character to Unicode

Function chinese2unicode(Str) Dim Str_one:Str_one = "" Dim Str_unicode:Str_unicode = "" For i = 1 To Len(Str) Str_one = Mid(Str, i, 1) If AscW(Str_one) < 0 or AscW(Str_one) > 255 Then Str_unicode = Str_unicode & Chr(38) Str_u

newLISP处理mysql escape character

什么是转义字符 mysql的escape character指的是需要转义的特殊字符,这些字符出现在sql语句中,如果没有转移会导致sql语法报错或者有sql注入攻击的可能. 主要有以下几种都需转义: \x00, \n, \r, \, ', " and \x1a. 比如' 就需要变成\' 下面是sql测试: mysql> INSERT INTO nodes(name) VALUES ('select a.dt, count(*), count(distinct a.uv) from (se

mysql 中 character set 与 collation

使用 mysql 创建数据表的时候, 总免不了要涉及到 character set 和 collation 的概念, 之前不是很了解. 这两天不是很忙, 就自己整理了一下. 先来看看 character set 和 collation 的是什么? &. character set, 即字符集. 我们常看到的 utf-8, GB2312, GB18030 都是相互独立的 character set. 即对 Unicode 的一套编码. 那么如何理解 unicode 与 utf-8, GB2312

MySQL中character set与collation的理解(转)

character set和collation的是什么? character set即字符集 我们常看到的UTF-8.GB2312.GB18030都是相互独立的character set.即对Unicode的一套编码. 那么如何理解Unicode与UTF-8.GB2312的区别呢? 打个比方,你眼前有一个苹果,在英文里称之为apple,而在中文里称之为苹果. 苹果这个实体的概念就是Unicode,而UTF-8,GB2312可以认为就是不同语言对苹果的不同称谓,本质上都是在描述苹果这个物. col

How to show Chinese character by using Perl?

You need to usemodule:  Unicode::Map Where to get it? -http://search.cpan.org/~mschwartz/Unicode-Map-0.112/Map.pm Download Unicode-Map-0.112.tar.gz How to install it? -unzip the file andgo the folder: C:\Users\rebecca\Desktop\Temp\Unicode-Map-0.112>p

html mysql special character

function html_encode(str) { var s = ""; if (str.length == 0) return ""; s = str.replace(/&/g, "&"); s = s.replace(/</g, "<"); s = s.replace(/>/g, ">"); //s = s.replace(/ /g, " &quo