当前位置: 首页 > 工具软件 > Olivia > 使用案例 >

MySQL字符集个人记录#Olivia丶长歌#

强硕
2023-12-01

MySQL配置文件关于字符集的设置

 [mysql]

default-character-set=gbk      从MySQL5.6开始系统所有的字符集都默认为utf8,这里个人设置为gbk

character-set-server=gbk     默认的字符集

collation_server = gbk_unicode_ci   服务器字符集校对规则


==========当前MySQL服务器字符集设置=========

mysql> show variables like 'character_set_%';
+--------------------------+----------------------------------+
| Variable_name            | Value                            |
+--------------------------+----------------------------------+
| character_set_client     | gbk                              |
| character_set_connection | gbk                              |
| character_set_database   | gbk                              |
| character_set_filesystem | binary                           |
| character_set_results    | gbk                              |
| character_set_server     | gbk                              |
| character_set_system     | utf8                             |
| character_sets_dir       | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)
=========查看库现有的字符集==============
mysql> show variables like '%char%';
+--------------------------+----------------------------------+
| Variable_name            | Value                            |
+--------------------------+----------------------------------+
| character_set_client     | gbk                              |
| character_set_connection | gbk                              |
| character_set_database   | gbk                              |
| character_set_filesystem | binary                           |
| character_set_results    | gbk                              |
| character_set_server     | gbk                              |
| character_set_system     | utf8                             |
| character_sets_dir       | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)
=========显示某数据库的字符集============
mysql> show create database olivia;
+----------+----------------------------------------------------------------        |
+----------+----------------------------------------------------------------+
| olivia   | CREATE DATABASE `olivia` /*!40100 DEFAULT CHARACTER SET gbk */ |
+----------+----------------------------------------------------------------+
1 row in set (0.00 sec)
========显示某数据表的字符集设置=========
mysql> show create table shangdian;
+-----------+--------------------------------------------------------------------------------------------------------------------------------+
| Table     | Create Table                                                                                                                   |
+-----------+--------------------------------------------------------------------------------------------------------------------------------+
| shangdian | CREATE TABLE `shangdian` (
  `riqi` int(11) DEFAULT NULL,
  `sal` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=gbk |
+-----------+--------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
===========修改数据库字符集===============
说明;alter database + 数据库名 + default character set 'UTF8';
===========修改数据表字符集===============
说明:alter table + 表名 + default character set 'UTF8';


set names gbk;临时设置字符集
 类似资料: