martes, 11 de octubre de 2016

Cambios en MySQL 5.6 a MySQL 5.7

Cambios en MySQL 5.6 a MySQL 5.7

Los cambios mas significativos cambios que tenemos que tomar en cuenta son los siguientes:


1) Insertar valores negativos en un campo tipo unsigned
Crear tabla con campo tipo unsigned:
CREATE TABLE test (
 id int unsigned
);
 
Insertar valor negativo: 
Previamente (en MySQL 56)
INSERT INTO test VALUES (-1);
Query OK, 1 row affected, 1 warning (0.01 sec) 
En MySQL 5.7: 
INSERT INTO test VALUES (-1);
ERROR 1264 (22003): Out of range value for column 'a' at row 1

2) Division por cero
Crear tabla de prueba: 
CREATE TABLE test2 (
 id int unsigned
); 
Dividiendo por 0 
Previamente: 
INSERT INTO test2 VALUES (0/0);
Query OK, 1 row affected (0.01 sec) 
En MySQL 5.7: 
INSERT INTO test2 VALUES (0/0);
ERROR 1365 (22012): Division by 0


3) Insertando 20 caracteres en una campo cadena en un campo de 10 caracteres
Crear table con campo tipo carácter de 10: 
CREATE TABLE test3 (
a varchar(10)
); 
Intentar insertar un valor mayor 
Previamente: 
INSERT INTO test3 VALUES ('abcdefghijklmnopqrstuvwxyz');
Query OK, 1 row affected, 1 warning (0.00 sec) 
En MySQL 5.7: 
INSERT INTO test3 VALUES ('abcdefghijklmnopqrstuvwxyz');
ERROR 1406 (22001): Data too long for column 'a' at row 1

4) Insertando una fecha en ceros en un campo tipo datetime
Creamos la tabla con el campo tipo datetime: 
CREATE TABLE test3 (
a datetime
); 
Insertar 0000-00-00 00:00:00. 
Previamente: 
INSERT INTO test3 VALUES ('0000-00-00 00:00:00');
Query OK, 1 row affected, 1 warning (0.00 sec) 
En 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) Usando GROUP BY and seleccionando columna ambigua:

Esto sucede cuando la descripción de la consulta no es parte de la sentencia GROUP BY, y/o que no hay funciones de agregación (MIN o MAX). 
Previamnete:
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) 
En 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