@@ -15,11 +15,11 @@ show variables like 'collation%';
15
15
vim /etc/mysql/my.cnf
16
16
17
17
[client]
18
- default-character-set=utf8mb4_bin
18
+ default-character-set=utf8mb4
19
19
20
20
[mysqld]
21
21
default-storage-engine=INNODB
22
- character-set-server=utf8mb4_bin
22
+ character-set-server=utf8mb4
23
23
collation-server=utf8mb4_bin
24
24
25
25
/etc/init.d/mysql stop
@@ -28,42 +28,50 @@ collation-server=utf8mb4_bin
28
28
29
29
``` mysql
30
30
-- 服务端
31
- set global character_set_server= utf8mb4_bin ;
32
- set global character_set_database= utf8mb4_bin ;
31
+ set global character_set_server = utf8mb4 ;
32
+ set global character_set_database = utf8mb4 ;
33
33
34
34
-- 客户端
35
- set global character_set_client= utf8mb4_bin ;
36
- set global character_set_connection= utf8mb4_bin ;
37
- set global character_set_results= utf8mb4_bin ;
35
+ set global character_set_client = utf8mb4 ;
36
+ set global character_set_connection = utf8mb4 ;
37
+ set global character_set_results = utf8mb4 ;
38
38
39
- create database if not exists ` db1` /* !40100 default character set utf8mb4_bin */ ;
39
+ create database if not exists ` db1` /* !40100 default character set utf8mb4 */ ;
40
40
41
- -- drop table if exists `db1_table1`;
42
- create table if not exists db1_table1
41
+ -- show create table db1_table0;
42
+ drop table if exists ` db1_table0` ;
43
+ create table if not exists db1_table0
43
44
(
44
- id bigint unsigned auto_increment comment ' 自增主键' ,
45
- create_time datetime not null comment ' 创建时间' ,
46
- update_time datetime null comment ' 更新时间' ,
47
- constraint db1_table1_pk primary key (id),
48
- constraint db1_table1_id_unique_index unique (id)
45
+ id bigint ( 20 ) unsigned not null auto_increment comment ' 自增主键' ,
46
+ create_time datetime( 6 ) not null default current_timestamp ( 6 ) comment ' 创建时间' ,
47
+ update_time datetime( 6 ) not null default current_timestamp ( 6 ) on update current_timestamp ( 6 ) comment ' 更新时间' ,
48
+ constraint db1_table1_pk primary key (id),
49
+ constraint db1_table1_id_unique_index unique (id)
49
50
) engine = InnoDB
50
- default charset = utf8mb4_bin comment = ' 表名' ;
51
+ default charset = utf8mb4
52
+ collate = utf8mb4_bin comment = ' 表名' ;
51
53
52
- -- 主键用id
54
+ -- show create table db1_table1;
55
+ drop table if exists ` db1_table1` ;
53
56
create table if not exists db1_table1
54
57
(
55
- id bigint unsigned auto_increment primary key unique comment ' 自增主键' ,
56
- create_time datetime not null comment ' 创建时间' ,
57
- update_time datetime null comment ' 更新时间'
58
- ) ENGINE = InnoDB
59
- DEFAULT CHARSET = utf8mb4_bin COMMENT = ' 表名' ;
58
+ id bigint (20 ) unsigned not null auto_increment primary key unique comment ' 自增主键' ,
59
+ create_time datetime(6 ) not null default current_timestamp (6 ) comment ' 创建时间' ,
60
+ update_time datetime(6 ) not null default current_timestamp (6 ) on update current_timestamp (6 ) comment ' 更新时间'
61
+ ) engine = InnoDB
62
+ default charset = utf8mb4
63
+ collate = utf8mb4_bin comment = ' 表名' ;
60
64
61
- -- show create table db1_table1;
62
- CREATE TABLE `db1_table1 ` (
63
- ` id` bigint (20 ) unsigned NOT NULL AUTO_INCREMENT COMMENT ' 自增主键' ,
64
- ` create_time` datetime NOT NULL COMMENT ' 创建时间' ,
65
- ` update_time` datetime DEFAULT NULL COMMENT ' 更新时间' ,
66
- PRIMARY KEY (` id` ),
67
- UNIQUE KEY ` id` (` id` )
68
- ) ENGINE= InnoDB DEFAULT CHARSET= utf8mb4_bin COMMENT= ' 表名'
65
+ -- show create table db1_table2;
66
+ drop table if exists ` db1_table2` ;
67
+ create table if not exists ` db1_table2`
68
+ (
69
+ ` id` bigint (20 ) unsigned not null auto_increment comment ' 自增序号' ,
70
+ ` create_time` datetime(6 ) not null default current_timestamp (6 ) comment ' 创建时间' ,
71
+ ` update_time` datetime(6 ) not null default current_timestamp (6 ) on update current_timestamp (6 ) comment ' 更新时间' ,
72
+ primary key (` id` ),
73
+ unique key ` id` (` id` )
74
+ ) engine = InnoDB
75
+ default charset = utf8mb4
76
+ collate = utf8mb4_bin comment = ' 表名' ;
69
77
```
0 commit comments