背景:

      之前介绍过 MySQL 5.5 新功能、参数,现在要用MySQL5.6,所以就学习和了解下MySQL5.6新的特性和功能,尽量避免踩坑。在后续的学习过程中文章也会不定时更新。

一:参数默认值的改变

Table Changes to Server Defaults in MySQL 5.6

Parameter Old Default New Default Version
back_log 50 Autosized usingmax_connections 5.6.6
binlog_checksum NONE CRC32 5.6.6
--binlog-row-event-max-size 1024 8192 5.6.6
flush_time 1800 (on Windows) 0 5.6.6
host_cache_size 128 Autosized usingmax_connections 5.6.8
innodb_autoextend_increment 8 64 5.6.6
innodb_buffer_pool_instances 1 8 (platform dependent) 5.6.6
innodb_concurrency_tickets 500 5000 5.6.6
innodb_data_file_path ibdata1:10M:autoextend ibdata1:12M:autoextend 5.6.7
innodb_file_per_table 0 1 5.6.6
innodb_log_file_size 5MB 48MB 5.6.8
innodb_old_blocks_time 0 1000 5.6.6
innodb_open_files 300 Autosized usinginnodb_file_per_table,table_open_cache 5.6.6
innodb_stats_on_metadata ON OFF 5.6.6
join_buffer_size 128KB 256KB 5.6.6
max_allowed_packet 1MB 4MB 5.6.6
max_connect_errors 10 100 5.6.6
open_files_limit 0 Autosized usingmax_connections 5.6.8
performance_schema OFF ON 5.6.6
performance_schema_events_waits_history_long_size 10000 Autosized 5.6.6
performance_schema_events_waits_history_size 10 Autosized 5.6.6
performance_schema_max_cond_instances 1000 Autosized 5.6.6
performance_schema_max_file_instances 10000 Autosized 5.6.6
performance_schema_max_mutex_instances 1000000 Autosized 5.6.6
performance_schema_max_rwlock_instances 1000000 Autosized 5.6.6
performance_schema_max_table_handles 100000 Autosized 5.6.6
performance_schema_max_table_instances 50000 Autosized 5.6.6
performance_schema_max_thread_instances 1000 Autosized 5.6.6
query_cache_size 0 1M 5.6.8
query_cache_type ON OFF 5.6.8
secure_auth OFF ON 5.6.7
sql_mode '' (empty string) NO_ENGINE_SUBSTITUTION 5.6.6
sync_master_info 0 10000 5.6.6
sync_relay_log 0 10000 5.6.6
sync_relay_log_info 0 10000 5.6.6
table_definition_cache 400 Autosized usingtable_open_cache 5.6.8
table_open_cache 400 2000 5.6.8
thread_cache_size 0 Autosized usingmax_connections 5.6.8

其中比较重要的参数:

表空间增长大小:innodb_autoextend_increment
是否独享表空间:innodb_file_per_table
查询information_schema元数据库里的表时,Innodb还会随机提取其他数据库每个表索引页的部分数据:innodb_stats_on_metadata
主从复制时候的刷写:sync_master_info、sync_relay_log、sync_relay_log_info

二 功能提升:

1)字段类型Timestampdatetime的改变:时间类型字段,4个字节。更多的信息见官方文档可以为表设置多个Timestamp的特性,且datetime类型支持DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP。 参考:MySQL5.6中TIMESTAMP的变化

时间戳。范围是'1970-01-01 00:00:00'到2037年。
TIMESTAMP列用于INSERT或UPDATE操作时记录日期和时间。如果你不分配一个值,表中的第一个TIMESTAMP列自动设置为最近操作的日期和时间。也可以通过分配一个NULL值,将TIMESTAMP列设置为当前的日期和时间。
TIMESTAMP值返回后显示为'YYYY-MM-DD HH:MM:SS'格式的字符串,显示宽度固定为19个字符。如果想要获得数字值,应在TIMESTAMP 列添加+0

 在MySQL 5.6.6之前,TIMESTAMP的默认行为:

  • TIMESTAMP列如果没有明确声明NULL属性,默认为NOT NULL。(而其他数据类型,如果没有显示声明为NOT NULL,则允许NULL值。)设置TIMESTAMP的列值为NULL,会自动存储为当前timestamp。
  • 表中的第一个TIMESTAMP列,如果没有声明NULL属性、DEFAULT或者 ON UPDATE,会自动分配 DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP 属性。
  • 表中第二个TIMESTAMP列,如果没有声明为NULL或者DEFAULT子句,默认自动分配’0000-00-00 00:00:00′。插入行时没有指明改列的值,该列默认分配’0000-00-00 00:00:00′,且没有警告。

Timestamp在5.5和5.6中的表现:5.6取消了一张表只有一个timestamp特性的限制。

MySQL 5.5:
zjy@192.168.210.245 : test 05:58:13>create table tmp_a(id int,a timestamp,b timestamp,c timestamp)engine = innodb default charset utf8;
Query OK, 0 rows affected (0.33 sec)

zjy@192.168.210.245 : test 05:58:50>show create table tmp_a\G;
*************************** 1. row ***************************
       Table: tmp_a
Create Table: CREATE TABLE `tmp_a` (
  `id` int(11) DEFAULT NULL,
  `a` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `b` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `c` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.01 sec)

#已经有了一个timestamp熟悉,再创建一个。 
zjy@192.168.210.245 : test 05:58:57>alter table tmp_a modify b timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;                                          
ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause   #失败

MySQL 5.6:
mysql> create table tmp_a(id int,a timestamp,b timestamp,c timestamp)engine = innodb default charset utf8;
Query OK, 0 rows affected (0.02 sec)

mysql> show create table tmp_a\G;
*************************** 1. row ***************************
       Table: tmp_a
Create Table: CREATE TABLE `tmp_a` (
  `id` int(11) DEFAULT NULL,
  `a` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `b` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `c` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

#已经有了一个timestamp熟悉,再创建一个。  
mysql> alter table tmp_a modify b timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; 
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table tmp_a modify c timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; 
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0
#成功
View Code

datetime 类型改进:支持DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAM。

mysql> show create table tmp_time\G;
*************************** 1. row ***************************
       Table: tmp_time
Create Table: CREATE TABLE `tmp_time` (
  `id` int(11) DEFAULT NULL,
  `day` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `cc` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1


mysql> select * from tmp_time;
+------+---------------------+---------------------+
| id   | day                 | cc                  |
+------+---------------------+---------------------+
|    1 | 2015-08-21 15:50:12 | 2015-08-21 15:50:12 |
|    2 | 2015-08-21 15:50:12 | 2015-08-21 15:50:12 |
+------+---------------------+---------------------+
View Code

相关文章: