{"record":{"id":"561255277064e582","repo":"iflytek/astron-agent","slug":"mysql-url-is-empty","errorCode":null,"errorMessage":"mysql url is empty","messagePattern":"mysql url is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tenant/tools/database/database.go","lineNumber":80,"sourceCode":"\n\tif err := initializeMysqlClient(client, conf.TenantBootstrap); err != nil {\n\t\t_ = client.Close()\n\t\treturn err\n\t}\n\n\tdb.mysql = client\n\treturn nil\n}\n\nfunc parseMysqlConfig(conf *config.Config) (string, *mysql.Config, error) {\n\tif len(conf.DataBase.UserName) == 0 {\n\t\treturn \"\", nil, errors.New(\"mysql username is empty\")\n\t}\n\tif len(conf.DataBase.Password) == 0 {\n\t\treturn \"\", nil, errors.New(\"mysql password is empty\")\n\t}\n\tif len(conf.DataBase.Url) == 0 {\n\t\treturn \"\", nil, errors.New(\"mysql url is empty\")\n\t}\n\tif err := conf.TenantBootstrap.Validate(); err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"invalid tenant bootstrap credentials: %w\", err)\n\t}\n\n\tdsn := fmt.Sprintf(\"%s:%s@tcp%s\", conf.DataBase.UserName, conf.DataBase.Password, conf.DataBase.Url)\n\tparsedDsn, err := mysql.ParseDSN(dsn)\n\tif err != nil {\n\t\treturn \"\", nil, err\n\t}\n\treturn dsn, parsedDsn, nil\n}\n\nfunc initializeMysqlClient(\n\tclient *sql.DB,\n\tcredentials config.TenantBootstrapCredentials,\n) error {\n\tif err := runMigrations(client); err != nil {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/tenant/tools/database/database.go#L62-L98","documentation":"parseMysqlConfig validates the MySQL section of the tenant service config before building a DSN. It throws 'mysql url is empty' when conf.DataBase.Url has zero length. The URL is the host:port portion used to assemble the go-sql-driver DSN (`user:pass@tcp<url>`), so without it no connection can be attempted.","triggerScenarios":"parseMysqlConfig (via buildMysql) runs with conf.DataBase.Url == \"\" — e.g. the config file omits database.url or the corresponding env var mapping is unset/unbound.","commonSituations":"Fresh deployments where the mysql host env var was never set; docker-compose/Helm values.yaml missing database.url; typo'd config key so the field fails to populate; running the tenant service locally without a config file.","solutions":["Set database.url in the tenant config (or the mapped env var) to a host:port value such as \"127.0.0.1:3306\" or \"mysql:3306\".","Verify the config file actually being loaded is the one you edited (check config load path logged at startup).","Confirm the env-var binding for the URL field is present in the deployment manifest and reachable in the container.","Check surrounding fields: the same validator also requires username and password, so fill all three together."],"exampleFix":"// before (config.yaml)\ndatabase:\n  username: tenant\n  password: secret\n# url missing\n\n// after\ndatabase:\n  username: tenant\n  password: secret\n  url: \"mysql:3306\"","handlingStrategy":"validation","validationCode":"func validateMysqlConfig(conf *config.Config) error {\n\tif conf.DataBase.Url == \"\" {\n\t\treturn errors.New(\"database.url must be set (host:port), e.g. mysql:3306\")\n\t}\n\treturn nil\n}\n// call before buildMysql","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a validated example config file in the repo and validate configs in CI before deploy.","Add a startup preflight that logs all required database fields (redacted) before connecting.","Use a config schema (envconfig/viper required tags) so missing fields fail with a clear message."],"tags":["mysql","config","database","go"],"backgroundTag":"missing-required-config-field","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}