{"record":{"id":"e0a56a9c1238d6de","repo":"micro/go-micro","slug":"couldn-t-create-table","errorCode":null,"errorMessage":"Couldn't create table","messagePattern":"Couldn't create table","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"store/mysql/mysql.go","lineNumber":158,"sourceCode":"}\n\nfunc (s *sqlStore) initDB() error {\n\t// Create the namespace's database\n\t_, err := s.db.Exec(fmt.Sprintf(\"CREATE DATABASE IF NOT EXISTS %s ;\", s.database))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t_, err = s.db.Exec(fmt.Sprintf(\"USE %s ;\", s.database))\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"Couldn't use database\")\n\t}\n\n\t// Create a table for the namespace's prefix\n\tcreateSQL := fmt.Sprintf(\"CREATE TABLE IF NOT EXISTS %s (`key` varchar(255) primary key, value blob null, expiry timestamp not null);\", s.table)\n\t_, err = s.db.Exec(createSQL)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"Couldn't create table\")\n\t}\n\n\t// prepare statements\n\tvar prepareErr error\n\n\ts.readPrepare, prepareErr = s.db.Prepare(fmt.Sprintf(\"SELECT `key`, value, expiry FROM %s.%s WHERE `key` = ?;\", s.database, s.table))\n\tif prepareErr != nil {\n\t\treturn errors.Wrap(prepareErr, \"failed to prepare read statement\")\n\t}\n\n\ts.writePrepare, prepareErr = s.db.Prepare(fmt.Sprintf(\"INSERT INTO %s.%s (`key`, value, expiry) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE `value`= ?, `expiry` = ?\", s.database, s.table))\n\tif prepareErr != nil {\n\t\treturn errors.Wrap(prepareErr, \"failed to prepare write statement\")\n\t}\n\n\ts.deletePrepare, prepareErr = s.db.Prepare(fmt.Sprintf(\"DELETE FROM %s.%s WHERE `key` = ?;\", s.database, s.table))\n\tif prepareErr != nil {\n\t\treturn errors.Wrap(prepareErr, \"failed to prepare delete statement\")","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/store/mysql/mysql.go#L140-L176","documentation":"initDB runs CREATE TABLE IF NOT EXISTS for the namespace's table after selecting the database; if MySQL rejects the DDL the store cannot operate and configure fails with this message. Typical causes are privileges, a reserved/invalid table name, or the database being unavailable.","triggerScenarios":"configure() -> initDB() executes the CREATE TABLE statement and MySQL returns an error (missing CREATE privilege, syntax/identifier issues from a bad namespace/table option, storage engine errors).","commonSituations":"MySQL user created without DDL rights; namespace containing illegal characters interpolated into the table name; MySQL in read-only mode; table name colliding with reserved words due to missing quoting.","solutions":["Check the wrapped MySQL error for the precise cause","Grant CREATE privilege: GRANT CREATE ON <db>.* TO '<user>'@'%';","Use a valid, simple namespace/table name (alphanumeric/underscore)","Ensure MySQL is writable (not read-only, disk not full)"],"exampleFix":"// before\nmysql.NewStore(store.Table(\"my-table 1\")) // invalid identifier\n// after\nmysql.NewStore(store.Table(\"micro_store\"))","handlingStrategy":"validation","validationCode":"// validate namespace before configure\nvar valid = regexp.MustCompile(`^[A-Za-z0-9_]+$`)\nif !valid.MatchString(namespace) {\n    return fmt.Errorf(\"invalid table name from namespace %q\", namespace)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use CREATE-privileged DB user or pre-create tables via migrations","Restrict namespaces to alphanumeric/underscore characters","Ensure MySQL is not in read-only mode (check super_read_only, disk space)","Smoke-test store configure in CI against a real MySQL"],"tags":["mysql","store","ddl","permissions"],"backgroundTag":"sql-table-creation-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}