{"record":{"id":"0ab945df3986e675","repo":"golang-migrate/migrate","slug":"no-database-name-0ab945","errorCode":null,"errorMessage":"no database name","messagePattern":"no database name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/mysql/mysql.go","lineNumber":35,"sourceCode":"\t\"sync/atomic\"\n\t\"time\"\n\n\t\"github.com/go-sql-driver/mysql\"\n\t\"github.com/golang-migrate/migrate/v4/database\"\n)\n\nvar _ database.Driver = (*Mysql)(nil) // explicit compile time type check\n\nfunc init() {\n\tdatabase.Register(\"mysql\", &Mysql{})\n}\n\nvar DefaultMigrationsTable = \"schema_migrations\"\n\nvar (\n\tErrDatabaseDirty    = fmt.Errorf(\"database is dirty\")\n\tErrNilConfig        = fmt.Errorf(\"no config\")\n\tErrNoDatabaseName   = fmt.Errorf(\"no database name\")\n\tErrAppendPEM        = fmt.Errorf(\"failed to append PEM\")\n\tErrTLSCertKeyConfig = fmt.Errorf(\"to use TLS client authentication, both x-tls-cert and x-tls-key must not be empty\")\n)\n\ntype Config struct {\n\tMigrationsTable  string\n\tDatabaseName     string\n\tNoLock           bool\n\tStatementTimeout time.Duration\n}\n\ntype Mysql struct {\n\t// mysql RELEASE_LOCK must be called from the same conn, so\n\t// just do everything over a single conn anyway.\n\tconn     *sql.Conn\n\tdb       *sql.DB\n\tisLocked atomic.Bool\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/mysql/mysql.go#L17-L53","documentation":"ErrNoDatabaseName in database/mysql is returned by WithInstance, Open and WithConnection when the database name resolved from the DSN or Config.DatabaseName is empty. MySQL needs the target schema to create/locate the schema_migrations table. The same sentinel also exists in cockroachdb, so the message may originate from either package.","triggerScenarios":"DSN without a database name (e.g. user:pass@tcp(host)/), Config.DatabaseName == \"\" with WithInstance/WithConnection, Open on a URL whose path is empty.","commonSituations":"DSN templates where the DB env var is unset, connection strings copied from tools that use a connect-time database selection, renaming a schema without updating migrate config.","solutions":["Include the schema in the DSN: user:pass@tcp(host:3306)/mydb","Set Config.DatabaseName explicitly for WithInstance/WithConnection","Fail fast in deployment config validation when the DB name env var is empty"],"exampleFix":"// before\nm, err := mysql.Open(\"user:pass@tcp(localhost:3306)/\")\n// after\nm, err := mysql.Open(\"user:pass@tcp(localhost:3306)/mydb\")","handlingStrategy":"validation","validationCode":"if cfg != nil && cfg.DatabaseName == \"\" {\n    return fmt.Errorf(\"MYSQL_DATABASE must be set or included in the DSN path\")\n}\n// for URL-based Open:\n// ensure \"tcp(host)/dbname\" contains a non-empty db segment","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if errors.Is(err, mysql.ErrNoDatabaseName) {\n        return fmt.Errorf(\"mysql DSN/config missing database name\")\n    }\n    return err\n}","preventionTips":["Include the schema name in every MySQL DSN","Validate required DB env vars at process startup","Prefer one DSN template so the db segment cannot be dropped"],"tags":["go","golang-migrate","mysql","config","missing-database-name"],"backgroundTag":"missing-database-name","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}