Unhandled database error with MySQL: Illegal mix of collations
See original GitHub issueThe problem
Recorder threw a MySQL warning on dismissal of an actionable notification. I’m on 2022.7.0b1. Recorder system status:
<html> <body> <div class="card-header" style="justify-content: space-between; display: flex; align-items: center; color: rgb(32, 33, 36); font-family: Roboto, Noto, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Recorder
</div>| Starttijd oudste run | 1 juni 2022 om 19:54 |
|---|---|
| Starttijd huidige run | 1 juli 2022 om 09:05 |
| Geschatte databasegrootte (MiB) | 236.08 MiB |
| Database-engine | mysql |
| Databaseversie | 10.8.3 |
What version of Home Assistant Core has the issue?
core-2022.7.0b1
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Container
Integration causing the issue
Recorder
Link to integration documentation on our website
https://www.home-assistant.io/integrations/recorder/
Diagnostics information
<html> <body>| Versie | core-2022.7.0b1 |
|---|---|
| Type installatie | Home Assistant Container |
| Ontwikkeling | false |
| Supervisor | false |
| Docker | true |
| Gebruiker | root |
| Virtuele omgeving | false |
| Python-versie | 3.10.5 |
| Besturingssysteem | Linux |
| Versie van het besturingssysteem | 4.19.0-20-amd64 |
| CPU-architectuur | x86_64 |
| Tijdzone | Europe/Amsterdam |
Example YAML snippet
No response
Anything in the logs that might be useful for us?
2022-07-01 09:09:28 ERROR (Recorder) [homeassistant.components.recorder.core] Unhandled database error while processing task EventTask(event=<Event mobile_app_notification_cleared[R]: action_1_title=🧹 Ja, graag!, notification_icon=mdi:robot-vacuum, channel=vacuum, action_2_title=Nee, dank je., action_2_key=vacuum_start_no, tag=vacuum, title=Rocky, message=Het is langer dan 24u geleden dat ik mijn laatste rondje heb gedaan. Zal ik gaan stofzuigen? 🧹🧹, action_1_key=vacuum_start_yes, device_id=7e28ad2dfcd33b37>): (MySQLdb.OperationalError) (1267, "Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb3_general_ci,COERCIBLE) for operation '='")
[SQL: SELECT event_data.data_id
FROM event_data
WHERE event_data.hash = %s AND event_data.shared_data = %s]
[parameters: (2507872631, '{"action_1_title":"🧹 Ja, graag!","notification_icon":"mdi:robot-vacuum","channel":"vacuum","action_2_title":"Nee, dank je.","action_2_key":"vacuum_st ... (63 characters truncated) ... dan 24u geleden dat ik mijn laatste rondje heb gedaan. Zal ik gaan stofzuigen? 🧹🧹","action_1_key":"vacuum_start_yes","device_id":"7e28ad2dfcd33b37"}')]
(Background on this error at: https://sqlalche.me/e/14/e3q8)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1819, in _execute_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute
cursor.execute(statement, parameters)
File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/usr/local/lib/python3.10/site-packages/MySQLdb/connections.py", line 254, in query
_mysql.connection.query(self, query)
MySQLdb.OperationalError: (1267, "Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb3_general_ci,COERCIBLE) for operation '='")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 610, in _process_one_task_or_recover
return task.run(self)
File "/usr/src/homeassistant/homeassistant/components/recorder/tasks.py", line 211, in run
instance._process_one_event(self.event)
File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 708, in _process_one_event
self._process_non_state_changed_event_into_session(event)
File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 773, in _process_non_state_changed_event_into_session
if data_id := self._find_shared_data_in_db(data_hash, shared_data):
File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 743, in _find_shared_data_in_db
if data_id := self.event_session.execute(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1712, in execute
result = conn._execute_20(statement, params or {}, execution_options)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1631, in _execute_20
return meth(self, args_10style, kwargs_10style, execution_options)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/lambdas.py", line 516, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1498, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1862, in _execute_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2043, in _handle_dbapi_exception
util.raise_(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 208, in raise_
raise exception
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1819, in _execute_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute
cursor.execute(statement, parameters)
File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/usr/local/lib/python3.10/site-packages/MySQLdb/connections.py", line 254, in query
_mysql.connection.query(self, query)
sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (1267, "Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb3_general_ci,COERCIBLE) for operation '='")
[SQL: SELECT event_data.data_id
FROM event_data
WHERE event_data.hash = %s AND event_data.shared_data = %s]
[parameters: (2507872631, '{"action_1_title":"🧹 Ja, graag!","notification_icon":"mdi:robot-vacuum","channel":"vacuum","action_2_title":"Nee, dank je.","action_2_key":"vacuum_st ... (63 characters truncated) ... dan 24u geleden dat ik mijn laatste rondje heb gedaan. Zal ik gaan stofzuigen? 🧹🧹","action_1_key":"vacuum_start_yes","device_id":"7e28ad2dfcd33b37"}')]
(Background on this error at: https://sqlalche.me/e/14/e3q8)
Additional information
No response
Issue Analytics
- State:
- Created a year ago
- Comments:16 (14 by maintainers)
Top Results From Across the Web
Illegal mix of collations MySQL Error - Stack Overflow
My database default collation stubbornly refuses to change from 'ucs2_bin' so even tried changing all the tables and the connection collation ...
Read more >Illegal mix of collations error in MySQL - utf8_unicode_ci and ...
This is generally caused by comparing two strings of incompatible collations or by attempting to select data of different collations into a ...
Read more >Illegal mix of collations for operation 'UNION' - Logbook won't ...
The problem Hey there! The errorlog below appears since updating to 2022.6 in general. I have waited with creating this issue till #73191 ......
Read more >MySQL error: Illegal mix of collations (utf8mb4_unicode_ci ...
MySQL error : Illegal mix of collations (utf8mb4_unicode_ci ... [homeassistant.components.recorder.core] Unhandled database error while ...
Read more >MariaDB Error Codes
MariaDB shares error codes with MySQL, as well as adding a number of new error ... 1267, HY000, ER_CANT_AGGREGATE_2COLLATIONS, Illegal mix of collations...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Found it…
Changing the connection string to
made it go away.
I guess this is due to setting up the DB before https://github.com/home-assistant/home-assistant.io/pull/15771, when the documented connection strings were listing just utf8
Let’s leave this open since we do want to do the migration eventually.