{"record":{"id":"841b81899c89ceac","repo":"MyCATApache/Mycat-Server","slug":"unknown-packet","errorCode":null,"errorMessage":"Unknown Packet!","messagePattern":"Unknown Packet!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/main/java/io/mycat/backend/mysql/nio/MySQLConnectionAuthenticator.java","lineNumber":106,"sourceCode":"\t\t\t\tErrorPacket err = new ErrorPacket();\n\t\t\t\terr.read(data);\n\t\t\t\tString errMsg = new String(err.message);\n\t\t\t\tLOGGER.warn(\"can't connect to mysql server ,errmsg:\"+errMsg+\" \"+source);\n\t\t\t\t//source.close(errMsg);\n\t\t\t\tthrow new ConnectionException(err.errno, errMsg);\n\n\t\t\tcase EOFPacket.FIELD_COUNT:\n\t\t\t\tauth323(data[3]);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tpacket = source.getHandshake();\n\t\t\t\tif (packet == null) {\n\t\t\t\t\tprocessHandShakePacket(data);\n\t\t\t\t\t// 发送认证数据包\n\t\t\t\t\tsource.authenticate();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new RuntimeException(\"Unknown Packet!\");\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t} catch (RuntimeException e) {\n\t\t\tif (listener != null) {\n\t\t\t\tlistener.connectionError(e, source);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\tprivate void processHandShakePacket(byte[] data) {\n\t\t// 设置握手数据包\n\t\tHandshakePacket packet= new HandshakePacket();\n\t\tpacket.read(data);\n\t\tsource.setHandshake(packet);","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/backend/mysql/nio/MySQLConnectionAuthenticator.java#L88-L124","documentation":"MySQLConnectionAuthenticator.handle throws RuntimeException(\"Unknown Packet!\") when the first bytes of the packet received during the MySQL authentication handshake are neither an OK, Error, nor EOF packet, and a handshake packet was already processed. This means the backend response did not follow the MySQL protocol, or the packet type byte was misread.","triggerScenarios":"Connecting to something that is not a standard MySQL server on the configured port (e.g. a proxy, proxy protocol mismatch, TLS/SSL mismatch where the server sends a TLS alert or HTML instead of a MySQL packet), or a corrupted/misframed stream.","commonSituations":"Datasource port pointing at an HTTP service or non-MySQL proxy; connecting with plaintext to a server that requires SSL, or vice versa; custom MySQL-protocol intermediaries sending nonstandard first packets.","solutions":["Verify the datasource host/port actually points at a MySQL server (run mysql -h host -P port -u user -p directly)","Check for TLS mismatch: align the datasource SSL settings with the server's require_secure_transport/ssl configuration","Capture the first bytes from that port (e.g. nc host port) — a valid MySQL handshake starts with a length + 0x0A protocol version; anything else means wrong target","Upgrade/inspect any MySQL proxy in the path that may emit nonstandard packets"],"exampleFix":"// before (schema.xml)\n<dataSource ... url=\"jdbc:mysql://host:8080/db\" /> <!-- 8080 is an HTTP service -->\n// after\n<dataSource ... url=\"jdbc:mysql://host:3306/db\" />","handlingStrategy":"retry","validationCode":"Socket s = new Socket(host, port);\nint first = s.getInputStream().read(); // MySQL greeting: length bytes then 0x0A protocol version; else wrong target\ns.close();\nif (first != 10 && first < 0) throw new IllegalStateException(\"Port \" + port + \" is not a MySQL server\");","typeGuard":null,"tryCatchPattern":"try { ... } catch (RuntimeException e) { if (\"Unknown Packet!\".equals(e.getMessage())) { log.error(\"Non-MySQL response from backend {}:{}; check port/TLS/proxy\", host, port); throw new ConfigException(\"Backend is not a MySQL server\", e); } throw e; }","preventionTips":["Point datasources only at verified MySQL endpoints (test with a raw mysql client)","Align TLS settings between mycat datasource config and the MySQL server","Audit any proxy/intermediary on the path for MySQL-protocol conformance","Include host:port in connection error logs to speed up misconfig diagnosis"],"tags":["mysql","protocol","handshake","connection"],"backgroundTag":"unexpected-response-shape","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}