## 查看数据库test_db的字符集
MySQL xz@(none):test_db> show create database test_db;
+----------+--------------------------------------------------------------------+
| Database | Create Database |
+----------+--------------------------------------------------------------------+
| test_db | CREATE DATABASE `test_db` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+----------+--------------------------------------------------------------------+
## 查看t1表单字符集
MySQL xz@(none):test_db> show create table t1;
+-------+---------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
------------------+
| Table | Create Table
|
+-------+---------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
------------------+
| t1 | CREATE TABLE `t1` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `name` varchar(20) DEFAULT NULL,\n `age` int(11) DE
FAULT NULL,\n `hight` int(11) DEFAULT NULL,\n `address` varchar(25) DEFAULT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEF
AULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
------------------+
## 修改数据库表字符集为utf8:
MySQL xz@(none):test_db> alter table t1 charset=utf8;
# 修改表字段的字符集为utf8:
MySQL xz@(none):test_db> alter table t1 modify 字段名 数据类型 charset utf8;
## 创建数据库指定数据库的字符集
MySQL xz@(none):test_db> create databases test_db charset utf8;
MySQL xz@(none):test_db> show create database test_db01;
+-----------+--------------------------------------------------------------------+
| Database | Create Database |
+-----------+--------------------------------------------------------------------+
| test_db01 | CREATE DATABASE `test_db01` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+-----------+--------------------------------------------------------------------+
## 查看数据库校验字符集
MySQL xz@(none):test_db> show collation;
MySQL xz@(none):test_db> show character set;
- ci:忽略大小写
- cs:区分大小写
## 创建数据库指定字符集及校验字符集
MySQL xz@(none):test_db> create database test_db02 charset=utf8 collate=utf8_bin;
MySQL - 数据库字符集
最新推荐文章于 2022-11-16 10:43:54 发布