MySQL字符集個人記錄#Olivia丶長歌#
阿新 • • 發佈:2019-02-02
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;臨時設定字符集