{"record":{"id":"88ca7e0f6ea1baff","repo":"MyCATApache/Mycat-Server","slug":"err-errno","errorCode":"err.errno","errorMessage":"errMsg","messagePattern":"errMsg","errorType":"exception","errorClass":"ConnectionException","httpStatus":null,"severity":"critical","filePath":"src/main/java/io/mycat/backend/mysql/nio/MySQLConnectionAuthenticator.java","lineNumber":93,"sourceCode":"\t\t\t\tsource.setHandler(new MySQLConnectionHandler(source));\n\t\t\t\tsource.setAuthenticated(true);\n\t\t\t\tboolean clientCompress = Capabilities.CLIENT_COMPRESS==(Capabilities.CLIENT_COMPRESS & packet.serverCapabilities);\n\t\t\t\tboolean usingCompress= MycatServer.getInstance().getConfig().getSystem().getUseCompression()==1 ;\n\t\t\t\tif(clientCompress&&usingCompress)\n\t\t\t\t{\n\t\t\t\t\tsource.setSupportCompress(true);\n\t\t\t\t}\n\t\t\t\tif (listener != null) {\n\t\t\t\t\tlistener.connectionAcquired(source);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase ErrorPacket.FIELD_COUNT:\n\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) {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/backend/mysql/nio/MySQLConnectionAuthenticator.java#L75-L111","documentation":"During the MySQL handshake/authentication phase, MySQLConnectionAuthenticator.handle received an ErrorPacket from the server and rethrows it as ConnectionException(err.errno, errMsg). The message 'can't connect to mysql server, errmsg:...' is logged first. This surfaces the MySQL server's own error (e.g. access denied, unknown database, max connections) at the mycat backend-connection layer.","triggerScenarios":"The backend MySQL server rejects the connection during authentication: wrong user/password in mycat's datasource config, host not allowed, too many connections, or server shutting down.","commonSituations":"Misconfigured user/password in schema.xml datasources; MySQL grants missing for the mycat host; server-side limits (max_connections, blocked host after failed logins).","solutions":["Read errMsg/errno in the exception to see the MySQL server's reason (1045=access denied, 1049=unknown database, 1040=too many connections)","Fix the datasource credentials in mycat config to match a MySQL account with access from the mycat host","Grant privileges: CREATE USER ...@'<mycat-host>'; GRANT ... and FLUSH PRIVILEGES on the MySQL server","Verify network reachability and that the MySQL server is accepting connections (mysql -h host -u user -p)"],"exampleFix":"// before (schema.xml datasource)\n<dataSource ... user=\"app\" password=\"wrongpass\" />\n// after\n<dataSource ... user=\"app\" password=\"correctpass\" /> <!-- matches MySQL grant for mycat host -->","handlingStrategy":"try-catch","validationCode":"try (Connection c = DriverManager.getConnection(url, user, password)) { /* validate credentials before registering datasource with mycat */ } catch (SQLException e) { /* fail fast */ }","typeGuard":null,"tryCatchPattern":"try { ... } catch (ConnectionException e) { if (e.getErrorCode() == 1045) { fix credentials } else if (e.getErrorCode() == 1040) { retry later / raise max_connections } else { alert ops with errno + errMsg } }","preventionTips":["Pre-test datasource credentials with a direct mysql client from the mycat host","Grant MySQL access for the mycat server host explicitly","Monitor and alert on the 'can't connect to mysql server' warn log","Keep datasource credentials in a managed secret, rotated with the DB grants"],"tags":["mysql","authentication","connection","error-packet"],"backgroundTag":"authentication-required","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"}