dog1888 发表于 2018-10-1 06:03:06

调整MySQL数据表字符集

  数据表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>>  Query OK, 0 rows affected (0.07 sec)
  Records: 0Duplicates: 0Warnings: 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>>  Query OK, 0 rows affected (0.71 sec)
  Records: 0Duplicates: 0Warnings: 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>>  Query OK, 0 rows affected (1.65 sec)
  Records: 0Duplicates: 0Warnings: 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)

页: [1]
查看完整版本: 调整MySQL数据表字符集