ITeye博客

MySQL字符集查看方法

yd514 · 2013-08-09 16:41 · Mysql · 数据库 · Markdown

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. +----------------------+-------------+-----------------+--------

四、修改字符集

 

//修改全局字符集

set character_set_connection=gb2312;

set character_set_database=gb2312;

set character_set_results=gb2312;

set character_set_server=gb2312;

set character_set_system=gb2312;

set collation_connection=gb2312;

set collation_database=gb2312;

set collation_server=gb2312;

 

//修改表的字符集 ALTER TABLE tb_name CONVERT TO CHARACTER SET gb2312;

 

//修改字段字符集 alter table tb_name modify column tb_column varchar(30) character set gb2312 not null;

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。