---
title: "MySQL字符集查看方法"
author: "yd514"
date: "2013-08-09T16:41:17Z"
tags: []
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2013-08-09T16:41:17Z"
id: 1922654
url: "https://yd514.iteye.com/blog/1922654"
---

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

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

01. mysql**&gt;** show variables like '%char%';
02. +--------------------------+-------------------------------------+------
03. | Variable\_name            | Value                               |......
04. +--------------------------+-------------------------------------+------
05. | character\_set\_client     | utf8                                |......   -- 客户端字符集
06. | character\_set\_connection | utf8                                |......
07. | character\_set\_database   | utf8                                |......   -- 数据库字符集
08. | character\_set\_filesystem | binary                              |......
09. | 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**&gt;** 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字符集。

01. mysql**&gt;** show full columns from countries;
02. +----------------------+-------------+-----------------+--------
03. | Field                | Type        | Collation       | .......
04. +----------------------+-------------+-----------------+--------
05. | countries\_id         | int(11)     | NULL            | .......
06. | countries\_name       | varchar(64) | utf8\_general\_ci | .......
07. | countries\_iso\_code\_2 | char(2)     | utf8\_general\_ci | .......
08. | countries\_iso\_code\_3 | char(3)     | utf8\_general\_ci | .......
09. | 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;