{"record":{"id":"c5cf6818dabb7cd4","repo":"remix-run/remix","slug":"mysql-database-config-requires-a-database-name","errorCode":null,"errorMessage":"MySQL database config requires a database name","messagePattern":"MySQL database config requires a database name","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/data-table-mysql/src/lib/driver.ts","lineNumber":533,"sourceCode":"\nfunction createMysqlConnection(config: string | MysqlPoolOptions): Promise<MysqlConnection> {\n  return typeof config === 'string'\n    ? mysql.createConnection(config)\n    : mysql.createConnection(config)\n}\n\nfunction isMysqlPool(client: MysqlQueryable): client is MysqlPool {\n  return 'getConnection' in client && typeof client.getConnection === 'function'\n}\n\nfunction resolveMysqlDatabaseName(config: string | MysqlPoolOptions): string {\n  let database =\n    typeof config === 'string'\n      ? resolveDatabaseNameFromUrl(config)\n      : (config.database ?? resolveDatabaseNameFromUrl(config.uri ?? ''))\n\n  if (!database) {\n    throw new Error('MySQL database config requires a database name')\n  }\n\n  return database\n}\n\nfunction resolveDatabaseNameFromUrl(value: string): string | undefined {\n  try {\n    let url = new URL(value)\n    let database = decodeURIComponent(url.pathname.replace(/^\\//, ''))\n    return database || undefined\n  } catch {\n    return undefined\n  }\n}\n\nfunction toMysqlServerConfig(config: string | MysqlPoolOptions): string | MysqlPoolOptions {\n  if (typeof config === 'string') {\n    try {","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/data-table-mysql/src/lib/driver.ts#L515-L551","documentation":"resolveMysqlDatabaseName extracts the database name from either a connection URL or a config object and throws when neither yields one. The MySQL driver needs an explicit database because migration locking and metadata queries depend on it; the name can come from config.database or the path component of config.uri (or a string URL).","triggerScenarios":"Passing a config with neither database nor uri; a uri without a path such as 'mysql://user:pass@host:3306'; a uri whose path is empty or malformed so resolveDatabaseNameFromUrl returns undefined.","commonSituations":"Environment-driven configs where MYSQL_URL omits the database; splitting a URL into components and dropping the path; typos like 'database' vs 'db' keys; test configs reusing a bare host DSN.","solutions":["Add the database name: { uri: 'mysql://user:pass@host:3306/mydb' } or { database: 'mydb', ... }","If using a URL string, verify it includes the path segment after the host","Check environment variables (e.g. MYSQL_URL/DATABASE_URL) actually contain the db name at runtime"],"exampleFix":"// before\nconst driver = createMysqlDriver({ uri: 'mysql://user:pass@localhost:3306' })\n// after\nconst driver = createMysqlDriver({ uri: 'mysql://user:pass@localhost:3306/app_db' })","handlingStrategy":"validation","validationCode":"import { parse } from 'node:url'\nfunction databaseNameFromUri(uri: string): string | undefined {\n  const path = parse(uri).pathname\n  return path ? path.replace(/^\\//, '') || undefined : undefined\n}\nif (!config.database && !databaseNameFromUri(config.uri ?? '')) {\n  throw new Error('add database to MySQL config or uri')\n}","typeGuard":"const configHasDatabase = (c: MysqlPoolOptions | string) =>\n  typeof c === 'string' ? /^[^/]+\\/.+/.test(c.split('://')[1] ?? '') : Boolean(c.database ?? c.uri?.match(/:\\d+\\/.+/))","tryCatchPattern":null,"preventionTips":["Include the db name in MYSQL_URL-style DSNs","Fail fast at boot validating config before constructing the driver"],"tags":["data-table","mysql","configuration","database-name"],"backgroundTag":"missing-database-config","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}