直接用中文名称即可查询。
可按如下方法做测试:
1、创建表插入数据:
create table test(序号 int,
名称 varchar(10))
insert into test values (1,'张三')
insert into test values (2,'李四')
2、执行查询:
select * from test where 序号=1结果显示:
也就是说中文字段名在查询中可以直接引用。
SELECT * FROM `tableA` WHERE LENGTH(`row_name`)<>CHARACTER_LENGTH(`row_name`)这样就能找出含有中文的记录了;如果查找全英文的记录,长度是相等的,把“<>”换成“=”就可以了,即
SELECT * FROM `tableA` WHERE LENGTH(`row_name`)=CHARACTER_LENGTH(`row_name`)
–查看字符集mysql>
show
variables
like
'character%'
mysql>
show
variables
like
'collation_%'
修改配置文件:
shell>
vi
/etc/mysql/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server
=
utf8_unicode_ci
init-connect=’SET
NAMES
utf8′
character-set-server
=
utf8
2.修改数据库:
mysql>ALTER
DATABASE
db_name
DEFAULT
CHARACTER
SET
character_name
[COLLATE
…]
3.把表默认的字符集和所有字符列(CHAR,VARCHAR,TEXT)改为新的字符集:
mysql>ALTER
TABLE
tbl_name
CONVERT
TO
CHARACTER
SET
character_name
[COLLATE
…]
mysql>ALTER
TABLE
logtest
CONVERT
TO
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
只是修改表的默认字符集:
mysql>ALTER
TABLE
tbl_name
DEFAULT
CHARACTER
SET
character_name
[COLLATE…]
mysql>ALTER
TABLE
logtest
DEFAULT
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
4.修改字段的字符集:
mysql>ALTER
TABLE
tbl_name
CHANGE
c_name
c_name
CHARACTER
SET
character_name
[COLLATE
…]
mysql>ALTER
TABLE
logtest
CHANGE
title
title
VARCHAR(100)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
5.临时更改连接字符集:mysql>
SET
NAMES
utf8
查看数据库的字符集
mysql>
show
create
database
test
查看表的字符集,包括各个字段的字符集,如果各字段没有标明,表示与表的字符集一致
mysql>
show
create
table
books
\G
查看字段编码
SHOW
FULL
COLUMNS
FROM
tbl_name
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)