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)