MySQL5.6到5.7版本升级采用IN-PLACE的升级方式需要具体关注的地方
一.SQL变更
GET_LOCK()函数行为
MySQL 5.7.5之前GET_LOCK()在执行第二次的额时候会释放前面获得的锁,在此版本以后支持同时获得多个锁,如:
mysql> select version();
+------------+
| version() |
+------------+
| 5.6.33-log |
+------------+
1 row in set (0.00 sec)
mysql> SELECT GET_LOCK('lock1',10);
+----------------------+
| GET_LOCK('lock1',10) |
+----------------------+
| 1 |
+----------------------+
1 row in set (0.00 sec)
mysql> SELECT GET_LOCK('lock2',10);
+----------------------+
| GET_LOCK('lock2',10) |
+----------------------+
| 1 |
+----------------------+
1 row in set (0.00 sec)
mysql> SELECT RELEASE_LOCK('lock2');
+-----------------------+
| RELEASE_LOCK('lock2') |
+-----------------------+
| 1 |
+-----------------------+
1 row in set (0.00 sec)
mysql> SELECT RELEASE_LOCK('lock1');
+-----------------------+
| RELEASE_LOCK('lock1') |
+-----------------------+
| NULL |
+-----------------------+
1 row in set (0.00 sec)
返回null说明此锁已经被释放了
所以依赖于释放任何先前锁的GET_LOCK()的行为的应用程序必须针对新行为进行修改。
二.derived_merge被自动开启
5.7中优化器使用一致的机制处理from语句中的派生表和视图是为了更好地避免不必要的物化并能够通过条件下放产生更有效的执行计划。
但是,对于修改表的语句(例如DELETE或UPDATE),使用先前物化的派生表的合并策略可能会导致ER_UPDATE_TABLE_USED错误:
错误原因:外部查询表和内部更改的表属于同一张表时,如果将派生表合并到外部查询块就会触发此错误(物化方式不会导致此错误,因为实际上,
它将派生表转换为单独的表)
如:
mysql> delete from t1 where id in (select t1.id from t1 inner join t2 using(id) where t2.a1=100);
ERROR 1093 (HY000): You can't specify target table 't1' for update in FROM clause
解决:关闭optimizer_switch的derived_merge选项,此选项默认是打开的
关闭derived_merge
SET optimizer_switch = 'derived_merge=off';
三.关键字和保留字
如果要引用保留字,必须使用反引号括起或跟在限定名称的逗点后,否则报语法错误,如
mysql> CREATE TABLE interval (begin INT, end INT);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'interval (begin INT, end INT)' at line 1
mysql> CREATE TABLE `interval` (begin INT, end INT);
Query OK, 0 rows affected (1.14 sec)
mysql> CREATE TABLE test.interval (begin INT, end INT);
Query OK, 0 rows affected (1.84 sec)
MySQL 5.7中有而MySQL 5.6中没有的关键字和保留字;有R标记的为保留字,见如下表格:
ACCOUNT ALWAYS CHANNEL
COMPRESSION ENCRYPTION FILE_BLOCK_SIZE
FILTER FOLLOWS GENERATED (R)
GROUP_REPLICATION INSTANCE JSON
MASTER_TLS_VERSION NEVER OPTIMIZER_COSTS (R)
PARSE_GCOL_EXPR PRECEDES REPLICATE_DO_DB
REPLICATE_DO_TABLE REPLICATE_IGNORE_DB REPLICATE_IGNORE_TABLE
REPLICATE_REWRITE_DB REPLICATE_WILD_DO_TABLE REPLICATE_WILD_IGNORE_TABLE
ROTATE STACKED STORED (R)
VALIDATION VIRTUAL (R) WITHOUT
XID
四.表联合查询
使用union连接的单个查询语句中如果有order by或limit关键字需要将此单个语句使用括号引起。如:
mysql> select * from t1 limit 1 union select * from t2 limit 2;
ERROR 1221 (HY000): Incorrect usage of UNION and LIMIT
mysql> (select * from t1 limit 1) union (select * from t2 limit 2);
+------+-------+-------+
| id | name1 | name2 |
+------+-------+-------+
| 1 | a1 | a2 |
| 1 | 2 | 2 |
| 1 | 1 | 1 |
+------+-------+-------+
3 rows in set (0.00 sec)