本文主要给大家介绍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> 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> 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 | .......
+----------------------+-------------+-----------------+--------
MysqL> show charset;
+----------+-----------------------------+---------------------+--------+
| Charset | Description | Default collation | Maxlen |
+----------+-----------------------------+---------------------+--------+
| big5 | Big5 Traditional Chinese | big5_chinese_ci | 2 |
| dec8 | DEC West European | dec8_swedish_ci | 1 |
| cp850 | DOS West European | cp850_general_ci | 1 |
| hp8 | HP West European | hp8_english_ci | 1 |
| koi8r | KOI8-R Relcom Russian | koi8r_general_ci | 1 |
| latin1 | cp1252 West European | latin1_swedish_ci | 1 |
| latin2 | ISO 8859-2 Central European | latin2_general_ci | 1 |
| swe7 | 7bit Swedish | swe7_swedish_ci | 1 |
| ascii | US ASCII | ascii_general_ci | 1 |
| ujis | EUC-JP Japanese | ujis_japanese_ci | 3 |
| sjis | Shift-JIS Japanese | sjis_japanese_ci | 2 |
| hebrew | ISO 8859-8 Hebrew | hebrew_general_ci | 1 |
| tis620 | TIS620 Thai | tis620_thai_ci | 1 |
| euckr | EUC-KR Korean | euckr_korean_ci | 2 |
| koi8u | KOI8-U Ukrainian | koi8u_general_ci | 1 |
| gb2312 | GB2312 Simplified Chinese | gb2312_chinese_ci | 2 |
| greek | ISO 8859-7 Greek | greek_general_ci | 1 |
| cp1250 | Windows Central European | cp1250_general_ci | 1 |
| gbk | GBK Simplified Chinese | gbk_chinese_ci | 2 |
| latin5 | ISO 8859-9 Turkish | latin5_turkish_ci | 1 |
| armscii8 | ARMSCII-8 Armenian | armscii8_general_ci | 1 |
| utf8 | UTF-8 Unicode | utf8_general_ci | 3 |
| ucs2 | UCS-2 Unicode | ucs2_general_ci | 2 |
| cp866 | DOS Russian | cp866_general_ci | 1 |
| keybcs2 | DOS Kamenicky Czech-Slovak | keybcs2_general_ci | 1 |
| macce | Mac Central European | macce_general_ci | 1 |
| macroman | Mac West European | macroman_general_ci | 1 |
| cp852 | DOS Central European | cp852_general_ci | 1 |
| latin7 | ISO 8859-13 Baltic | latin7_general_ci | 1 |
| cp1251 | Windows Cyrillic | cp1251_general_ci | 1 |
| cp1256 | Windows arabic | cp1256_general_ci | 1 |
| cp1257 | Windows Baltic | cp1257_general_ci | 1 |
| binary | Binary pseudo charset | binary | 1 |
| geostd8 | GEOSTD8 Georgian | geostd8_general_ci | 1 |
| cp932 | SJIS for Windows Japanese | cp932_japanese_ci | 2 |
| eucjpms | UJIS for Windows Japanese | eucjpms_japanese_ci | 3 |
+----------+-----------------------------+---------------------+--------+
以上查看 MysqL 字符集命令,适用于 Windows & Linux
find / -iname '*.cnf' -print
/usr/share/MysqL/my-innodb-heavy-4G.cnf
/usr/share/MysqL/my-large.cnf
/usr/share/MysqL/my-small.cnf
/usr/share/MysqL/my-medium.cnf
/usr/share/MysqL/my-huge.cnf
/usr/share/texmf/web2c/texmf.cnf
/usr/share/texmf/web2c/mktex.cnf
/usr/share/texmf/web2c/fmtutil.cnf
/usr/share/texmf/tex/xmltex/xmltexfmtutil.cnf
/usr/share/texmf/tex/jadetex/jadefmtutil.cnf
/usr/share/doc/MysqL-server-community-5.1.22/my-innodb-heavy-4G.cnf
/usr/share/doc/MysqL-server-community-5.1.22/my-large.cnf
/usr/share/doc/MysqL-server-community-5.1.22/my-small.cnf
/usr/share/doc/MysqL-server-community-5.1.22/my-medium.cnf
/usr/share/doc/MysqL-server-community-5.1.22/my-huge.cnf
2. 拷贝 small.cnf、my-medium.cnf、my-huge.cnf
my-innodb-heavy-4G.cnf,其中的一个到/etc下命名为my.cnf
cp /usr/share/MysqL/my-medium.cnf /etc/my.cnf
3. 修改my.cnf
vi /etc/my.cnf
在[client]下添加
default-character-set=utf8
在[MysqLd]下添加
default-character-set=utf8
4.重新启动MysqL
[root@bogon ~]# /etc/rc.d/init.d/MysqL restart
Shutting down MysqL [ 确定 ]
Starting MysqL. [ 确定 ]
[root@bogon ~]# MysqL -u root -p
Enter password:
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 1
Server version: 5.1.22-rc-community-log MysqL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
其他的一些设置方法:
MysqL>use mydb
MysqL>alter database mydb character set utf-8;
创建数据库指定数据库的字符集
MysqL>create database mydb character set utf-8;
修改/var/lib/MysqL/mydb/db.opt
default-character-set=latin1
default-collation=latin1_swedish_ci
为
default-character-set=utf8
default-collation=utf8_general_ci
重起MysqL:
[root@bogon ~]# /etc/rc.d/init.d/MysqL restart
MysqL> set character_set_client=utf8;
Query OK, 0 rows affected (0.00 sec)
MysqL> set character_set_connection=utf8;
Query OK, 0 rows affected (0.00 sec)
MysqL> set character_set_database=utf8;
Query OK, 0 rows affected (0.00 sec)
MysqL> set character_set_results=utf8;
Query OK, 0 rows affected (0.00 sec)
MysqL> set character_set_server=utf8;
Query OK, 0 rows affected (0.00 sec)
MysqL> set character_set_system=utf8;
Query OK, 0 rows affected (0.01 sec)
MysqL> set collation_connection=utf8;
Query OK, 0 rows affected (0.01 sec)
MysqL> set collation_database=utf8;
Query OK, 0 rows affected (0.01 sec)
MysqL> set collation_server=utf8;
Query OK, 0 rows affected (0.01 sec)
查看 数据库表中字段的字符集是否为utf8的 如果不是 还要设置字段为utf8格式的!
看了以上关于MysqL数据库的字符集讲义,希望能给大家在实际运用中带来一定的帮助。本文由于篇幅有限,难免会有不足和需要补充的地方,如有需要更加专业的解答,可在官网联系我们的24小时售前售后,随时帮您解答问题的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。