{"record":{"id":"94fdf6f44c136d8f","repo":"micro/go-micro","slug":"failed-to-prepare-delete-statement","errorCode":null,"errorMessage":"failed to prepare delete statement","messagePattern":"failed to prepare delete statement","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store/mysql/mysql.go","lineNumber":176,"sourceCode":"\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\")\n\t}\n\n\treturn nil\n}\n\nfunc (s *sqlStore) configure() error {\n\tnodes := s.options.Nodes\n\tif len(nodes) == 0 {\n\t\tnodes = []string{\"localhost:3306\"}\n\t}\n\n\tdatabase := s.options.Database\n\tif len(database) == 0 {\n\t\tdatabase = DefaultDatabase\n\t}\n\n\ttable := s.options.Table\n\tif len(table) == 0 {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/store/mysql/mysql.go#L158-L194","documentation":"initDB prepares the DELETE statement used by sqlStore.Delete; failure aborts store configuration. As with the other prepare steps, this almost always means a dead connection or invalid interpolated SQL identifiers.","triggerScenarios":"configure() -> initDB() prepares `DELETE FROM <db>.<table> WHERE key = ?` and db.Prepare errors, typically as the last of the three prepares after an earlier connection drop.","commonSituations":"MySQL restart or network blip mid-configure; invalid namespace characters in the table identifier; server-side prepared statement limits or restrictions reached.","solutions":["Inspect the wrapped cause for the MySQL error code","Validate database/table identifiers derived from the namespace","Retry configure/recreate the store after connection recovery","Check max_prepared_stmt_count and proxy restrictions on the server"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if err := db.Ping(); err != nil {\n    return fmt.Errorf(\"mysql unreachable before store configure: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := st.Init(opts...); err != nil {\n    if strings.Contains(err.Error(), \"failed to prepare delete statement\") {\n        time.Sleep(time.Second)\n        return st.Init(opts...)\n    }\n    return err\n}","preventionTips":["Ensure a stable connection for all three prepares (read/write/delete)","Validate namespace-derived table names","Watch prepared statement limits and proxy behavior","Retry Init on transient failures"],"tags":["mysql","store","prepare","sql"],"backgroundTag":"sql-prepare-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}