MyCATApache/Mycat-Server · critical · RuntimeException
Unknown Packet!
Error message
Unknown Packet!
What it means
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.
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
Example fix
// before (schema.xml) <dataSource ... url="jdbc:mysql://host:8080/db" /> <!-- 8080 is an HTTP service --> // after <dataSource ... url="jdbc:mysql://host:3306/db" />
Defensive patterns
Strategy: retry
Validate before calling
Socket s = new Socket(host, port);
int first = s.getInputStream().read(); // MySQL greeting: length bytes then 0x0A protocol version; else wrong target
s.close();
if (first != 10 && first < 0) throw new IllegalStateException("Port " + port + " is not a MySQL server"); Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- err.errno
- Unknown charsetIndex:
- unknown status!
- ER_UNKNOWN_COM_ERROR
- global seq and share join and special…
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/841b81899c89ceac.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/backend/mysql/nio/MySQLConnectionAuthenticator.java:106
ErrorPacket err = new ErrorPacket();
err.read(data);
String errMsg = new String(err.message);
LOGGER.warn("can't connect to mysql server ,errmsg:"+errMsg+" "+source);
//source.close(errMsg);
throw new ConnectionException(err.errno, errMsg);
case EOFPacket.FIELD_COUNT:
auth323(data[3]);
break;
default:
packet = source.getHandshake();
if (packet == null) {
processHandShakePacket(data);
// 发送认证数据包
source.authenticate();
break;
} else {
throw new RuntimeException("Unknown Packet!");
}
}
} catch (RuntimeException e) {
if (listener != null) {
listener.connectionError(e, source);
return;
}
throw e;
}
}
private void processHandShakePacket(byte[] data) {
// 设置握手数据包
HandshakePacket packet= new HandshakePacket();
packet.read(data);
source.setHandshake(packet);View on GitHub (pinned to 65f8d8beb7)