MySQL字符集编码查看 修改。

修改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字符集。

  
  
  1. mysql> show variables like '%char%';

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

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

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

  
  
  1. mysql> show full columns from countries;  

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

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

  
  
  1. mysql> show variables like '%char%';  
  2. +--------------------------+-------------------------------------+------  
  3. | Variable_name            | Value                               |......  
  4. +--------------------------+-------------------------------------+------  
  5. | character_set_client     | utf8                                |......   -- 客户端字符集  
  6. | character_set_connection | utf8                                |......  
  7. | character_set_database   | utf8                                |......   -- 数据库字符集  
  8. | character_set_filesystem | binary                              |......  
  9. | character_set_results    | utf8                                |......  
  10. | character_set_server     | utf8                                |......   -- 服务器字符集  
  11. | character_set_system     | utf8                                |......  
  12. | character_sets_dir       | D:\MySQL Server 5.0\share\charsets\ |......  
  13. +--------------------------+-------------------------------------+------ 

 

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

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

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

  
  
  1. mysql> show full columns from countries;  
  2. +----------------------+-------------+-----------------+--------  
  3. | Field                | Type        | Collation       | .......  
  4. +----------------------+-------------+-----------------+--------  
  5. | countries_id         | int(11)     | NULL            | .......  
  6. | countries_name       | varchar(64) | utf8_general_ci | .......  
  7. | countries_iso_code_2 | char(2)     | utf8_general_ci | .......  
  8. | countries_iso_code_3 | char(3)     | utf8_general_ci | .......  
  9. | address_format_id    | int(11)     | NULL            | .......  
  10. +----------------------+-------------+-----------------+--------  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值