{"record":{"id":"2573d9732f84961e","repo":"apache/shardingsphere","slug":"1253","errorCode":"1253","errorMessage":"COLLATION '%s' is not valid for CHARACTER SET '%s'","messagePattern":"COLLATION '(.+?)' is not valid for CHARACTER SET '(.+?)'","errorType":"exception","errorClass":"CollationCharsetMismatchException","httpStatus":null,"severity":"error","filePath":"proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutor.java","lineNumber":197,"sourceCode":"                && variableAssigns.subList(1, 4).stream().allMatch(each -> first.getStartIndex() == each.getStartIndex() && first.getStopIndex() == each.getStopIndex());\n    }\n    \n    private MySQLSessionCharsetContext updateCharsetContext(final MySQLSessionCharsetContext context, final VariableAssignSegment variableAssign,\n                                                            final boolean setNamesWithCollationAssignment) {\n        String variableName = variableAssign.getVariable().getVariable().toLowerCase(Locale.ROOT);\n        switch (variableName) {\n            case CHARACTER_SET_CLIENT:\n                return context.withClientCharacterSet(setNamesWithCollationAssignment\n                        ? parseCharacterSet(variableAssign.getAssignValue())\n                        : parseClientCharacterSet(variableAssign.getAssignValue()));\n            case CHARACTER_SET_RESULTS:\n                return updateResultCharacterSet(context, variableAssign.getAssignValue());\n            case CHARACTER_SET_CONNECTION:\n                return context.withConnectionCollation(parseConnectionCharacterSet(variableAssign.getAssignValue()));\n            case COLLATION_CONNECTION:\n                MySQLCharacterSets collation = parseCollation(variableAssign.getAssignValue());\n                if (setNamesWithCollationAssignment && !context.getConnectionCharacterSetName().equals(collation.getCharacterSetName())) {\n                    throw new CollationCharsetMismatchException(collation.getCollationName(), context.getConnectionCharacterSetName());\n                }\n                if (setNamesWithCollationAssignment) {\n                    validateClientCharacterSet(context.getClientCharacterSetName());\n                }\n                return context.withConnectionCollation(collation);\n            default:\n                return context;\n        }\n    }\n    \n    private MySQLCharacterSets parseClientCharacterSet(final String value) {\n        String normalizedValue = formatVariableValue(value).toLowerCase(Locale.ROOT);\n        validateClientCharacterSet(normalizedValue);\n        return parseCharacterSet(value);\n    }\n    \n    private void validateClientCharacterSet(final String characterSet) {\n        if (IMPERMISSIBLE_CLIENT_CHARACTER_SETS.contains(characterSet)) {","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutor.java#L179-L215","documentation":"CollationCharsetMismatchException (error code 1253, MySQL error semantics) thrown by MySQLSetVariableAdminExecutor when processing SET NAMES ... COLLATE <collation>: the parsed collation's character set name must equal the already-established connection character set name. MySQL requires a collation to belong to the charset it is applied to; the proxy enforces the same rule before accepting context.withConnectionCollation(collation).","triggerScenarios":"SET NAMES utf8mb4 COLLATE latin1_bin (collation belongs to latin1, not utf8mb4), or SET NAMES followed by SET COLLATION_CONNECTION to a collation from a different charset while setNamesWithCollationAssignment is true: context.getConnectionCharacterSetName() != collation.getCharacterSetName() triggers the throw.","commonSituations":"Copy-pasted SET NAMES statements mixing charset and collation from different families; client drivers defaulting one charset while app code overrides only the collation; migrating configs from utf8 to utf8mb4 and updating only half of the pair.","solutions":["Pair the collation with its own charset: SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci (check MySQL's information_schema.COLLATIONS for the mapping)","If you only need the collation, set COLLATION_CONNECTION alone without a SET NAMES collation clause, keeping the existing charset consistent","Align driver charset/collation properties (characterEncoding, connectionCollation) so they reference the same charset family"],"exampleFix":"-- before\nSET NAMES utf8mb4 COLLATE latin1_swedish_ci;\n\n-- after\nSET NAMES utf8mb4 COLLATE utf8mb4_0900_ai_ci;","handlingStrategy":"validation","validationCode":"// client-side pre-check: collation must belong to the charset being set\nif (!collation.getCharacterSetName().equals(charsetName)) {\n    throw new IllegalArgumentException(\"Collation \" + collationName\n            + \" belongs to \" + collation.getCharacterSetName() + \", not \" + charsetName);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always generate SET NAMES collation from the same charset family (utf8mb4 -> utf8mb4_*)","Fetch the charset->collation mapping from information_schema.COLLATIONS when building SET statements dynamically"],"tags":["mysql","charset","collation","set-names","validation"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}