{"record":{"id":"e02087d741765ced","repo":"MyCATApache/Mycat-Server","slug":"errmessage-loaddata","errorCode":null,"errorMessage":"{errMessage} -> {loadData}","messagePattern":"\\{errMessage\\} -> \\{loadData\\}","errorType":"exception","errorClass":"DataMigratorException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/util/dataMigrator/dataIOImpl/MysqlDataIO.java","lineNumber":71,"sourceCode":"\t\tString user = dn.getUserName();\n\t\tString pwd = dn.getPwd();\n\t\tString db = dn.getDb();\n\n//\t\tString loadData =\"?mysql -h? -P? -u? -p? -D? --local-infile=1 -e \\\"load data local infile '?' replace into table ? CHARACTER SET '?' FIELDS TERMINATED BY ','  LINES TERMINATED BY '\\\\r\\\\n'\\\"\";\n\t\tString loadData = \"?mysql -h? -P? -u? -p? -D?  -f --default-character-set=? -e \\\"source ?\\\"\";\n\t\tloadData = DataMigratorUtil.paramsAssignment(loadData,\"?\",mysqlBin,ip,port,user,pwd,db,charset,file.getAbsolutePath());\n\t\tLOGGER.info(table.getSchemaAndTableName()+\" \"+loadData);\n\t\tProcess process = DataMigratorUtil.exeCmdByOs(loadData);\n\n\t\t//获取错误信息\n\n\t\tInputStreamReader in = new InputStreamReader(process.getErrorStream(),isWindows()?\"GBK\": Charset.defaultCharset().name());\n\t\tBufferedReader br = new BufferedReader(in);\n\t\tString errMessage = null;\n        while ((errMessage = br.readLine()) != null) {\n            if(errMessage.trim().toLowerCase().contains(\"err\")){\n            \tSystem.out.println(errMessage+\" -> \"+loadData);\n            \tthrow new DataMigratorException(errMessage+\" -> \"+loadData);\n            }\n        }\n\n\t\tprocess.waitFor();\n\t}\n\n\t@Override\n\tpublic File exportData(TableMigrateInfo table,DataNode dn, String tableName, File export, File condition) throws IOException, InterruptedException {\n\t\tString ip = dn.getIp();\n\t\tint port = dn.getPort();\n\t\tString user = dn.getUserName();\n\t\tString pwd = dn.getPwd();\n\t\tString db = dn.getDb();\n\n//\t\tString mysqlDump = \"?mysqldump -h? -P? -u? -p? ? ?  --no-create-info --default-character-set=? \"\n//\t\t\t\t+ \"--add-locks=false --tab='?' --fields-terminated-by=',' --lines-terminated-by='\\\\r\\\\n' --where='? in(?)'\";\n\t\t//由于mysqldump导出csv格式文件只能导出到本地，暂时替换成导出insert形式的文件\n\t\tString mysqlDump = \"?mysqldump -h? -P? -u? -p? ? ?  --compact --no-create-info --default-character-set=? --add-locks=false --where=\\\"? in (#)\\\" --result-file=\\\"?\\\" \";","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/util/dataMigrator/dataIOImpl/MysqlDataIO.java#L53-L89","documentation":"During data migration import, MysqlDataIO runs the mysql client (load data infile) as an external process and scans its stderr line by line. Any stderr line whose lowercase text contains the substring \"err\" is treated as a fatal import failure and wrapped in a DataMigratorException with the offending line and the loadData command. Because the check is a naive substring match, even benign stderr output containing 'err' (e.g. 'Warning: ... error_log') aborts the migration.","triggerScenarios":"Calling importData for a table where the spawned mysql load-data process writes any stderr line containing 'err', e.g. incorrect CSV field counts, missing data file, wrong LOAD DATA syntax, or MySQL connection/auth failure of the child process.","commonSituations":"Data file path not readable by mysqld (secure_file_priv restrictions), column count/separator mismatch between the migrated file and target table, wrong character set (GBK vs UTF-8 on Windows), or mysql client not on PATH producing a command-not-found error on stderr.","solutions":["Run the printed loadData command manually and fix the underlying MySQL load-data error (file path, permissions, column list, separators).","Check mysqld's secure_file_priv and local_infile settings and ensure the data file is in an allowed location with read permission for the mysql user.","Verify the mysql client binary exists and is executable, and that credentials in the migration config are correct.","On Windows, confirm the expected GBK console output decoding matches the child process encoding so error lines are parsed correctly."],"exampleFix":"// before\nString sql = \"load data infile '\" + file + \"' into table \" + table + \";\";\n// after\nString sql = \"load data local infile '\" + file.replace(\"\\\\\", \"/\") + \"' into table \" + table\n    + \" character set utf8mb4 fields terminated by ',' enclosed by '\\\"' lines terminated by '\\n';\";","handlingStrategy":"validation","validationCode":"// before import\nFile dataFile = new File(dataPath);\nif (!dataFile.isFile() || !dataFile.canRead()) throw new IllegalStateException(\"data file unreadable: \" + dataPath);\n// verify target table columns match file\ntry (Connection c = DriverManager.getConnection(jdbcUrl, user, pass)) {\n  ResultSet rs = c.createStatement().executeQuery(\"SELECT COUNT(*) FROM \" + table);\n  rs.next();\n}","typeGuard":null,"tryCatchPattern":"try {\n  dataIO.importData(...);\n} catch (DataMigratorException e) {\n  logger.error(\"load data failed: {}\", e.getMessage()); // run the loadData command manually to debug\n}","preventionTips":["Test the exact loadData SQL against one small file before full migration.","Verify mysqld's secure_file_priv/local_infile and file permissions beforehand.","Confirm column count and separators in the data file match the target table."],"tags":["data-migration","external-process","mysql","load-data"],"backgroundTag":"database-write-failed","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"}