這篇文章將為大家詳細(xì)講解有關(guān)升級(jí)到MySQL5.7版本需注意的問題有哪些,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
10年積累的成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有余慶免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
升級(jí)到MySQL5.7 版本需注意的問題
1)在一個(gè)無符號(hào)列中插入一個(gè)負(fù)值
創(chuàng)建具有無符號(hào)列的表:CREATE TABLE test (id int unsigned);
插入負(fù)值。
以前版本:INSERT INTO test VALUES (-1);
Query OK, 1 row affected, 1 warning (0.01 sec)
MySQL 5.7版本:
INSERT INTO test VALUES (-1);
ERROR 1264 (22003): Out of range value for column 'a' at row 1
2)除以零
創(chuàng)建測(cè)試表:CREATE TABLE test2 ( id int unsigned );
嘗試除以零。
先前版本:INSERT INTO test2 VALUES (0/0);
Query OK, 1 row affected (0.01 sec)
MySQL 5.7版本:INSERT INTO test2 VALUES (0/0);
ERROR 1365 (22012): Division by 0
3)在10個(gè)字符的列中插入20個(gè)字符的字符串
創(chuàng)建一個(gè)包含10個(gè)字符的列的表:CREATE TABLE test3 ( a varchar(10) );
嘗試插入較長的字符串。
先前版本:INSERT INTO test3 VALUES ('abcdefghijklmnopqrstuvwxyz');
Query OK, 1 row affected, 1 warning (0.00 sec)
MySQL 5.7版本:INSERT INTO test3 VALUES ('abcdefghijklmnopqrstuvwxyz');
ERROR 1406 (22001): Data too long for column 'a' at row 1
4)將非標(biāo)準(zhǔn)零日期插入日期時(shí)間列
創(chuàng)建具有datetime列的表:CREATE TABLE test3 ( a datetime );
插入0000-00-00 00:00:00 。
先前版本:INSERT INTO test3 VALUES ('0000-00-00 00:00:00');
Query OK, 1 row affected, 1 warning (0.00 sec)
MySQL 5.7版本:INSERT INTO test3 VALUES ('0000-00-00 00:00:00');
ERROR 1292 (22007): Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1
5)使用GROUP BY并選擇一個(gè)不明確的列
發(fā)生這種情況時(shí)的說明不是一部分GROUP BY ,并且沒有聚集函數(shù)(例如MIN或MAX )施加到其上。
先前版本:SELECT id, invoice_id, description FROM invoice_line_items GROUP BY invoice_id;
+----+------------+-------------+
| id | invoice_id | description |
+----+------------+-------------+
| 1 | 1 | New socks |
| 3 | 2 | Shoes |
| 5 | 3 | Tie |
+----+------------+-------------+
3 rows in set (0.00 sec)
MySQL 5.7版本:SELECT id, invoice_id, description FROM invoice_line_items GROUP BY invoice_id;
ERROR 1055 (42000): Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'invoice_line_items.description' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
5)mysql5.7版本SQL_MODE
默認(rèn)情況下,MySQL 5.7包含以下模式:
* ONLY_FULL_GROUP_BY
* STRICT_TRANS_TABLES
* NO_ENGINE_SUBSTITUTION
* NO_AUTO_CREATE_USER
該模式STRICT_TRANS_TABLES也變得更加嚴(yán)格,在mysql 5.7中,默認(rèn)使用的是嚴(yán)格模式,有時(shí)候可能帶來問題,
比如:
mysql> CREATE TABLE `events_t` (
-> `id` int(11) NOT NULL AUTO_INCREMENT,
-> `event_date` datetime NOT NULL,
-> `profile_id` int(11) DEFAULT NULL,
-> PRIMARY KEY (`id`),
-> KEY `event_date` (`event_date`),
-> KEY `profile_id` (`profile_id`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=latin1
-> ;
Query OK, 0 rows affected (0.02 sec)
mysql> insert into events_t (profile_id) values (1);
ERROR 1364 (HY000): Field 'event_date' doesn't have a default value
這里日期就必須要有默認(rèn)值,不能 NULL,但:
mysql> alter table events_t change event_date event_date datetime NOT NULL default '0000-00-00 00:00:00';
ERROR 1067 (42000): Invalid default value for 'event_date'
mysql> alter table events_t change event_date event_date datetime NOT NULL default '2000-00-00 00:00:00';
ERROR 1067 (42000): Invalid default value for 'event_date'
也是不行的,必須要有真實(shí)日期默認(rèn)
mysql> alter table events_t change event_date event_date datetime NOT NULL default '2000-01-01 00:00:00';
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> insert into events_t (profile_id) values (1);
Query OK, 1 row affected (0.00 sec)
因此只有日期格式改為timestamp,或者用NULL,或者在insert的時(shí)候用now()產(chǎn)生日期。
6)mysql-connector-java.Jar
Table 2.1 Summary of Connector/J Versions
Connector/J version | Driver Type | JDBC version | MySQL Server version | Status |
5.1 | 4 | 3.0, 4.0, 4.1, 4.2 | 4.1, 5.0, 5.1, 5.5, 5.6, 5.7 | Recommended version |
5.0 | 4 | 3.0 | 4.1, 5.0 | Released version |
3.1 | 4 | 3.0 | 4.1, 5.0 | Obsolete |
3.0 | 4 | 3.0 | 3.x, 4.1 | Obsolete |
Table 26.2 MySQL Connector Versions and MySQL Server Versions
Connector | Connector version | MySQL Server version |
Connector/C | 6.1.0 GA | 5.6, 5.5, 5.1, 5.0, 4.1 |
Connector/C++ | 1.0.5 GA | 5.6, 5.5, 5.1 |
Connector/J | 5.1.8 | 5.6, 5.5, 5.1, 5.0, 4.1 |
Connector/Net | 6.5 | 5.6, 5.5, 5.1, 5.0 |
Connector/Net | 6.4 | 5.6, 5.5, 5.1, 5.0 |
Connector/Net | 6.3 | 5.6, 5.5, 5.1, 5.0 |
Connector/Net | 6.2 (No longer supported) | 5.6, 5.5, 5.1, 5.0 |
Connector/Net | 6.1 (No longer supported) | 5.6, 5.5, 5.1, 5.0 |
Connector/Net | 6.0 (No longer supported) | 5.6, 5.5, 5.1, 5.0 |
Connector/Net | 5.2 (No longer supported) | 5.6, 5.5, 5.1, 5.0 |
Connector/Net | 1.0 (No longer supported) | 5.0, 4.0 |
Connector/ODBC | 5.1 | 5.6, 5.5, 5.1, 5.0, 4.1.1+ |
Connector/ODBC | 3.51 (Unicode not supported) | 5.6, 5.5, 5.1, 5.0, 4.1 |
Connector/Python | 2.0 | 5.7, 5.6, 5.5 |
Connector/Python | 1.2 | 5.7, 5.6, 5.5 |
關(guān)于“升級(jí)到MySQL5.7版本需注意的問題有哪些”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。