您的位置:首页 > 数据库 > MySQL

MySQL字符集编码查看 修改。

2012-11-08 11:28 543 查看
修改my.ini文件,加上
default-character-set=gb2312

设定数据库字符集

alter database da_name default character set 'charset'

1)设置数据库编码 /etc/my.cnf

[mysqld]

default-character-set=gbk

...

[client]

default-character-set=gbk

---------------------------------------

2)按字符集导出

$mysqldump -u root -p dbname --default-character-set=gbk > a.sql;

3)查看SQL文件的编码

[root@localhost gethtml]# file a.sql

a.sql: UTF-8 Unicode ...

[root@localhost gethtml]# iconv -f utf-8 -t gbk a.sql > a2.sql

[root@localhost gethtml]# file a2.sql

a2.sql: Non-ISO extended-ASCII English text 这时已经是gbk的编码了

3)导入

查看数据库服务和客户端字符集

mysql> status;

Server characterset: gbk

Db characterset: gbk

Client characterset: latin1

Conn. characterset: latin1

mysql> set names 'gbk'; //这样

mysql> status;

Server characterset: gbk

Db characterset: gbk

Client characterset: gbk

Conn. characterset: gbk

这时才能导数据

mysql> source a.sql;

----------------------------------------------------------------------------------

单独设置某个数据库:

alter database testdb character set utf8;

查看mysql支持的编码:

show character set;

查看系统的字符集和排序方式的设定可以通过下面的两条命令:

mysql> SHOW VARIABLES LIKE ''character_set_%'';

客户端连接的时候设置编码方式:

mysql -uxxx -p dbName --default-character-set=utf8

一、查看MySQL数据库服务器和数据库MySQL字符集。

mysql> show variables like '%char%';


二、查看MySQL数据表(table)的MySQL字符集。

mysql> show table status from dbName like '%tbName%';

三、查看MySQL数据列(column)的MySQL字符集。

mysql> show full columns from countries;


MySQL字符集多种多样,下面为列举了其中三种最常见的字符集查看方法,该方法供您参考,希望对学习MySQL数据库能有所启迪。

一、查看MySQL数据库服务器和数据库MySQL字符集。

mysql> show variables like '%char%';  
+--------------------------+-------------------------------------+------  
| Variable_name            | Value                               |......  
+--------------------------+-------------------------------------+------  
| character_set_client     | utf8                                |......   -- 客户端字符集  
| character_set_connection | utf8                                |......  
| character_set_database   | utf8                                |......   -- 数据库字符集  
| character_set_filesystem | binary                              |......  
| character_set_results    | utf8                                |......  
| character_set_server     | utf8                                |......   -- 服务器字符集  
| character_set_system     | utf8                                |......  
| character_sets_dir       | D:\MySQL Server 5.0\share\charsets\ |......  
+--------------------------+-------------------------------------+------



二、查看MySQL数据表(table)的MySQL字符集。

mysql> show table status from sqlstudy_db like '%countries%';  
+-----------+--------+---------+------------+------+-----------------+------  
| Name      | Engine | Version | Row_format | Rows | Collation       |......  
+-----------+--------+---------+------------+------+-----------------+------  
| countries | InnoDB |      10 | Compact    |   11 | utf8_general_ci |......  
+-----------+--------+---------+------------+------+-----------------+------

三、查看MySQL数据列(column)的MySQL字符集。

mysql> show full columns from countries;  
+----------------------+-------------+-----------------+--------  
| Field                | Type        | Collation       | .......  
+----------------------+-------------+-----------------+--------  
| countries_id         | int(11)     | NULL            | .......  
| countries_name       | varchar(64) | utf8_general_ci | .......  
| countries_iso_code_2 | char(2)     | utf8_general_ci | .......  
| countries_iso_code_3 | char(3)     | utf8_general_ci | .......  
| address_format_id    | int(11)     | NULL            | .......  
+----------------------+-------------+-----------------+--------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: