Error de mezcla ilegal de intercalaciones en MySQL


Acabo de recibir esta respuesta de una pregunta anterior y funciona un placer!

SELECT username, (SUM(rating)/COUNT(*)) as TheAverage, Count(*) as TheCount 
FROM ratings WHERE month='Aug' GROUP BY username HAVING TheCount > 4
ORDER BY TheAverage DESC, TheCount DESC

Pero cuando pego este bit extra en él da este error:

Documentación #1267-Mezcla ilegal de intercalación (latin1_swedish_ci,IMPLÍCITO) y (latin1_general_ci, IMPLÍCITO) para operación " = "

SELECT username, (SUM(rating)/COUNT(*)) as TheAverage, Count(*) as TheCount FROM 
ratings WHERE month='Aug' 
**AND username IN (SELECT username FROM users WHERE gender =1)**
GROUP BY username HAVING TheCount > 4 ORDER BY TheAverage DESC, TheCount DESC

La tabla es:

id, username, rating, month

Author: Rikesh, 2009-08-07

16 answers

Compruebe el tipo de intercalación de cada tabla y asegúrese de que tienen la misma intercalación.

Después de eso compruebe también el tipo de intercalación de cada campo de tabla que tiene en funcionamiento.

Me había encontrado con el mismo error, y que los trucos funciona en mí.

 13
Author: bluish,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-01-16 13:12:45

Aquí está cómo comprobar qué columnas son la intercalación incorrecta:

SELECT table_schema, table_name, column_name, character_set_name, collation_name

FROM information_schema.columns

WHERE collation_name = 'latin1_general_ci'

ORDER BY table_schema, table_name,ordinal_position; 

Y aquí está la consulta para solucionarlo:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET latin1 COLLATE 'latin1_swedish_ci';

Link

 67
Author: Dean Rather,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-02-06 23:59:30

[MySQL]

En estos casos (muy raros):

  • dos tablas que realmente necesitan diferentes tipos de intercalación
  • Valores que no provienen de una tabla, sino de una enumeración explícita, por ejemplo:

    SELECCIONE 1 COMO números UNION ALL SELECT 2 UNION ALL SELECT 3

Puede comparar los valores entre las diferentes tablas utilizando CAST o CONVERT:

CAST('my text' AS CHAR CHARACTER SET utf8)

CONVERT('my text' USING utf8)

Ver CONVERTIR y EMITIR documentación en el sitio web de MySQL.

 8
Author: RotS,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-17 11:58:34

Estaba recibiendo este mismo error en phpMyAdmin e hice la solución indicada aquí que funcionó para mí

ALTER TABLE table CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci

Mezcla ilegal de intercalaciones MySQL Error También recomendaría ir con General en lugar de sueco ya que uno es predeterminado y no usar el idioma a menos que su aplicación esté utilizando sueco.

 5
Author: pal4life,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:34:44
  • Compruebe que sus usuarios.la columna de género es un ENTERO.
  • Intenta: alter table users convert to character set latin1 collate latin1_swedish_ci;
 1
Author: hobodave,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-08-06 22:31:51

Necesita cambiar cada colación de columna de latin1_general_ci a latin1_swedish_ci

 1
Author: Swadesh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-25 17:50:31

Tengo este mismo error dentro de un procedimiento almacenado, en la cláusula where. descubrí que el problema ocurría con una variable declarada local, previamente cargada por la misma tabla / columna.

Lo resolví fundiendo los datos al tipo char único.

 1
Author: Roberto Camargo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-23 13:49:01

En resumen, este error es causado por MySQL tratando de hacer una operación en dos cosas que tienen diferentes configuraciones de intercalación. Si hace que la configuración coincida, el error desaparecerá. Por supuesto, debe elegir la configuración correcta para su base de datos, dependiendo de para qué se va a usar.

Aquí hay algunos buenos consejos para elegir entre dos colaciones utf8 muy comunes: ¿Cuál es la diferencia entre utf8_general_ci y utf8_unicode_ci

Si está utilizando phpMyAdmin puede hacer esto sistemáticamente trabajando a través de las tablas mencionadas en su mensaje de error y verificando el tipo de intercalación para cada columna. Primero debe verificar cuál es la configuración general de intercalación para su base de datos: phpMyAdmin puede decirle esto y cambiarlo si es necesario. Pero cada columna en cada tabla puede tener su propia configuración. Normalmente querrá que todos estos coincidan.

En una pequeña base de datos esto es bastante fácil de hacer a mano, y en cualquier caso si lee el error mensaje en su totalidad por lo general le indicará el lugar correcto. No olvides mirar la configuración de 'estructura' para las columnas con subtablas también. Cuando encuentre una intercalación que no coincida, puede cambiarla usando phpMyAdmin directamente, sin necesidad de usar la ventana de consulta. Entonces intente su operación de nuevo. Si el error persiste, sigue buscando!

 1
Author: Pinkeye,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:10:31

Creo que deberías convertir a utf8

--set utf8 for connection
SET collation_connection = 'utf8_general_ci'
--change CHARACTER SET of DB to utf8
ALTER DATABASE dbName CHARACTER SET utf8 COLLATE utf8_general_ci
--change CHARACTER SET of table to utf8
ALTER TABLE tableName CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci
 1
Author: Quy Le,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-03 06:53:20

El problema aquí principalmente, simplemente Cast el campo como este cast(campo como varchar) o cast (campos como fecha)

 1
Author: reds,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-07 07:01:12
SELECT  username, AVG(rating) as TheAverage, COUNT(*) as TheCount
FROM    ratings
        WHERE month='Aug'
        AND username COLLATE latin1_general_ci IN
        (
        SELECT  username
        FROM    users
        WHERE   gender = 1
        )
GROUP BY
        username
HAVING
        TheCount > 4
ORDER BY
        TheAverage DESC, TheCount DESC;
 0
Author: Quassnoi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-08-06 22:48:01

Use ascii_bin siempre que sea posible, coincidirá con casi cualquier intercalación. Un nombre de usuario rara vez acepta caracteres especiales de todos modos.

 0
Author: Kjeld Flarup,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-24 11:46:00

Si desea evitar cambiar la sintaxis para resolver este problema, pruebe esto:

Actualice su MySQL a la versión 5.5 o superior.

Esto resolvió el problema para mí.

 0
Author: HoldOffHunger,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-13 13:49:16

Tengo el mismo problema con la advertencia de colección para un campo que se establece de 0 a 1. Todas las colecciones de columnas eran iguales. Intentamos cambiar las colecciones de nuevo, pero nada soluciona este problema.

Al final actualizamos el campo a NULL y después actualizamos a 1 y esto supera el problema de la colección.

 0
Author: glg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-07 12:37:51
HAvING TheCount > 4 AND username IN (SELECT username FROM users WHERE gender=1)

Pero por qué estoy respondiendo, no me votaste como respuesta correcta:)

 -1
Author: Rufinus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-08-06 22:27:53

Asegúrese de que su versión de MySQL soporta subconsultas (4.1+). A continuación, puede intentar reescribir su consulta a algo como esto:

SELECT ratings.username, (SUM(rating)/COUNT(*)) as TheAverage, Count(*) as TheCount FROM ratings, users 
WHERE ratings.month='Aug' and ratings.username = users.username
AND users.gender = 1
GROUP BY ratings.username
HAVING TheCount > 4 ORDER BY TheAverage DESC, TheCount DESC
 -2
Author: stereoscott,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-08-06 22:27:49