码迷,mamicode.com
首页 > 数据库 > 详细

调整MySQL数据表字符集

时间:2018-03-14 14:50:39      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:charset   collate   

数据表t1表的结构.

mysql> show create table t1\G

*************************** 1. row ***************************

       Table: t1

Create Table: CREATE TABLE `t1` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `account` varchar(30) NOT NULL DEFAULT '',

  PRIMARY KEY (`id`),

  UNIQUE KEY `uniq_account` (`account`)

) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8

1 row in set (0.00 sec)



1. 调整默认charset为utf8mb4.

mysql> alter table t1 default charset utf8mb4;

Query OK, 0 rows affected (0.07 sec)

Records: 0  Duplicates: 0  Warnings: 0


mysql> show create table t1\G

*************************** 1. row ***************************

       Table: t1

Create Table: CREATE TABLE `t1` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `account` varchar(30) CHARACTER SET utf8 NOT NULL DEFAULT '',

  PRIMARY KEY (`id`),

  UNIQUE KEY `uniq_account` (`account`)

) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4

1 row in set (0.00 sec)



2. 调整account字段collate为utf8mb4_bin.

mysql> alter table t1 modify column account varchar(30) collate utf8mb4_bin not null default '';

Query OK, 0 rows affected (0.71 sec)

Records: 0  Duplicates: 0  Warnings: 0


mysql> show create table t1\G

*************************** 1. row ***************************

       Table: t1

Create Table: CREATE TABLE `t1` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `account` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '',

  PRIMARY KEY (`id`),

  UNIQUE KEY `uniq_account` (`account`)

) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4

1 row in set (0.00 sec)



3. 调整默认charset, 和各字段charset为utf8.

mysql> alter table t1 convert to charset utf8;

Query OK, 0 rows affected (1.65 sec)

Records: 0  Duplicates: 0  Warnings: 0


mysql> show create table t1\G

*************************** 1. row ***************************

       Table: t1

Create Table: CREATE TABLE `t1` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `account` varchar(30) NOT NULL DEFAULT '',

  PRIMARY KEY (`id`),

  UNIQUE KEY `uniq_account` (`account`)

) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8

1 row in set (0.00 sec)

调整MySQL数据表字符集

标签:charset   collate   

原文地址:http://blog.51cto.com/coveringindex/2086732

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!