Since MySQL 8.0.27, multithreading is now enabled by default for replica servers. Source
Until then, if the replication failed, we could get the exact error from Last_Error in the result of show replica status\G;. Now, the query is replaced by "Anonymous":
Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction 'ANONYMOUS' at master log mysql-bin.031116, end_log_pos 81744270. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
The table performance_schema.replication_applier_status_by_worker does not contain the exact error either:
mysql> select * from performance_schema.replication_applier_status_by_worker\G
*************************** 1. row ***************************
CHANNEL_NAME:
WORKER_ID: 1
THREAD_ID: 128
SERVICE_STATE: ON
LAST_ERROR_NUMBER: 0
LAST_ERROR_MESSAGE:
LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00.000000
LAST_APPLIED_TRANSACTION: ANONYMOUS
LAST_APPLIED_TRANSACTION_ORIGINAL_COMMIT_TIMESTAMP: 2021-11-16 11:35:04.414021
LAST_APPLIED_TRANSACTION_IMMEDIATE_COMMIT_TIMESTAMP: 2021-11-16 11:35:04.414021
LAST_APPLIED_TRANSACTION_START_APPLY_TIMESTAMP: 2021-11-16 11:35:04.416898
LAST_APPLIED_TRANSACTION_END_APPLY_TIMESTAMP: 2021-11-16 11:35:04.420018
APPLYING_TRANSACTION:
APPLYING_TRANSACTION_ORIGINAL_COMMIT_TIMESTAMP: 0000-00-00 00:00:00.000000
APPLYING_TRANSACTION_IMMEDIATE_COMMIT_TIMESTAMP: 0000-00-00 00:00:00.000000
APPLYING_TRANSACTION_START_APPLY_TIMESTAMP: 0000-00-00 00:00:00.000000
LAST_APPLIED_TRANSACTION_RETRIES_COUNT: 0
LAST_APPLIED_TRANSACTION_LAST_TRANSIENT_ERROR_NUMBER: 0
LAST_APPLIED_TRANSACTION_LAST_TRANSIENT_ERROR_MESSAGE:
LAST_APPLIED_TRANSACTION_LAST_TRANSIENT_ERROR_TIMESTAMP: 0000-00-00 00:00:00.000000
APPLYING_TRANSACTION_RETRIES_COUNT: 0
APPLYING_TRANSACTION_LAST_TRANSIENT_ERROR_NUMBER: 0
APPLYING_TRANSACTION_LAST_TRANSIENT_ERROR_MESSAGE:
APPLYING_TRANSACTION_LAST_TRANSIENT_ERROR_TIMESTAMP: 0000-00-00 00:00:00.000000
-- <I've removed 3 other similar blocks>
I can indeed find the error in the MySQL error log (e.g. "Could not execute Write_rows event on table db.table; Duplicate entry '16737' for key 'table.PRIMARY'"), but not from a query anymore.
Is there another query that would give me this last error message? Or a specific setting to log it & display it under show replica status\G;?