1

I'm migrating a WordPress website to a dedicated server, and am encountering the infamous "Error establishing a database connection" error. I've read similar questions, and a number of blog posts on the subject, but I'm still stuck:

  • My main page says "Error establishing a database connection"
  • My wp-admin page says "One or more database tables are unavailable. The database may need to be repaired."

I've performed the following verifications:

  • I've verified the credentials in wp-config.php. When using them on the command-line, I can access the database, and have all access rights to create tables, and CRUD rows.
  • I have defined WP_DEBUG and WP_DEBUG_DISPLAY in wp-config.php, but the error message is still as vague.
  • I have defined WP_ALLOW_REPAIR in wp-config.php and executed /wp-admin/maint/repair.php:

The wp_users table is okay.
The wp_usermeta table is okay.
The wp_posts table is okay.
The wp_comments table is okay.
The wp_links table is okay.
The wp_options table is okay.
The wp_postmeta table is okay.
The wp_terms table is okay.
The wp_term_taxonomy table is okay.
The wp_term_relationships table is okay.
The wp_commentmeta table is okay.
Repairs complete.

Yet, I'm still getting the same error messages.

I'm starting to wonder if the backup I was given (I did not make this backup) contains all the required tables. Here are the tables that were in the backup:

  • wp_adrotate
  • wp_adrotate_groups
  • wp_adrotate_linkmeta
  • wp_adrotate_schedule
  • wp_adrotate_stats
  • wp_adrotate_tracker
  • wp_cntctfrm_field
  • wp_commentmeta
  • wp_comments
  • wp_duplicator_packages
  • wp_ewwwio_images
  • wp_links
  • wp_options
  • wp_postmeta
  • wp_posts
  • wp_term_relationships
  • wp_term_taxonomy
  • wp_terms
  • wp_usermeta
  • wp_users
  • wp_wpmm_subscribers

What can be causing this error? Is there a way to get a detailed error message?

The WordPress version is 4.1.16 and the DB revision is 30135.

1

You appear to be missing the wp_termmeta table, which I'm guessing was omitted from the backup.

Here's a 'create table' syntax for this table (you may have to tweak this depending on your MySQL version)

CREATE TABLE `wp_termmeta` (
  `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `term_id` bigint(20) unsigned NOT NULL DEFAULT '0',
  `meta_key` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
  `meta_value` longtext COLLATE utf8mb4_unicode_520_ci,
  PRIMARY KEY (`meta_id`),
  KEY `term_id` (`term_id`),
  KEY `meta_key` (`meta_key`(191))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
  • Here is a version from a different one of my local DBs in case this is more helpful: CREATE TABLE wp_termmeta` ( meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT, term_id bigint(20) unsigned NOT NULL DEFAULT '0', meta_key varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, meta_value longtext COLLATE utf8_unicode_ci, PRIMARY KEY (meta_id), KEY term_id (term_id), KEY meta_key (meta_key(191)) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;` – Jonny Perl Mar 27 '17 at 12:49
  • I did try creating this table, but the error persists I'm afraid! – Benjamin Mar 27 '17 at 13:55
  • sorry to hear it! I note that you are using an older WP version. Does your codebase match (ie are you using the files for version 4.1.16)? Have you tried using the latest WordPress and just letting it try to update the database? – Jonny Perl Mar 27 '17 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.