Title: Error Establishing Database Connection
Last modified: August 30, 2016

---

# Error Establishing Database Connection

 *  [bayworth](https://wordpress.org/support/users/bayworth/)
 * (@bayworth)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-94/)
 * Dear All I am pulling my hair out and need help. I will try and explain my perils
   in logical order not using the real domains.
 * I installed Worpress under one of my domains e.g. Mydomain1.com
    My provider 
   is oneandone so wordpress was installed directly from my control panel and all
   worked fine. It asked me to create my database and username etc. I installed 
   a theme and everything worked fine. This was using an old domain I had and used
   for testing. I then dicided that I wanted to move the site to one of my new domains
   e.g. Mydomain2.com which is actually part of the same hosting package as mydomain1.
   So I followed all the procedures on the wordpress site. First I did a new install
   of worpress under the new domain2.com. This created a second database with a 
   new name and new login. Then I backed up all the files in the original domain1.
   com and I also backed up the original database (lets call it DB1) by exporting
   it from phpadmin panel. I then uploaded all my backed files to the new location
   of mydomain2.com overwriting any files created as part of the worpress install(
   i think this was my mistake point). I then imported the old database into the
   new database i.e. DB1 (from domain1.com) to DB2 (domain2.com). I then loggedinto
   the wordpress admin panel and using the plug in “Backup and Replace” I replaced
   all occurences of the old domain1.com with the new domain2.com. This seemed to
   work fine. Finally I then went and edited the old wp-config file and updated 
   it the the new database name DB2, new database user DB2 and new database host
   DB2.DB.1and1.com . In the old file there the host name also had :3306 which I
   have tried with and without. The tricky part was the database password entry.
   In the old WP-config file it had a rather large string of mixed characters and
   I dont know where this came from. I assume it has created this automatically.
   Anyway I have tried leaving this the same and also changing it to the new password
   that was assigned to the new database when I created it. In all cases when I 
   save the wp-config file I end up getting the message “error establishing database
   connection”. This messages appears on my webpage as soon as I type in the domain2.
   com Also I can no longer get into my admin panel. So I think I have really screw
   something up but I am not sure at what step. Can someone please offer advice 
   and corrective actions. Im a bit of a newbie so keep it simple please.

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [leejosepho](https://wordpress.org/support/users/leejosepho/)
 * (@leejosepho)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-94/#post-6502407)
 * First go to cPanel > MySQL and collect this information:
 * DB1 name:
    DB1 user: DB1 password: (change it if you cannot read it)
 * DB2 name:
    DB2 user: DB2 password: (change it if you cannot read it)
 * Next go to cPanel phpMyAdmin and get this information:
 * DB1 table_prefix:
    DB2 table_prefix: note: At my own host, I have an extra SQL
   user assigned to both databases so I can use those credentials to see both databases
   at once at phpMyAdmin.
 * After gathering the above info, open your two wp-config.php files side-by-side
   and make certain each has what it should from the above.
 * If you might be uncertain about each or either site’s URL in the database, edit
   this and temporarily add it at the top of the respective wp-config.php file/s:
 * Select and edit one pair of lines or the other — no trailing slashes — then temporarily
   place a slash after `/*toggle on/off*` just above them to un-comment them and
   make them active.
 *     ```
       /*-either-*/
       /* tell database to recognize and use http://domain.com
       /** @ near top of wp-config.php /*toggle on/off*
       define('WP_HOME','http://domain.com');
       define('WP_SITEURL','http://domain.com');
       /*-or-*/
       /* tell database to recognize and use http://www.domain.com
       /** @ near top of wp-config.php /*toggle on/off*
       define('WP_HOME','http://www.domain.com');
       define('WP_SITEURL','http://www.domain.com');
       /*-end-*/
       ```
   
 * If you use the above and still have URL trouble, maybe try this in your active
   theme’s functions.php:
 * Select and edit one pair of lines or the other — no trailing slashes — then temporarily
   place a slash after `/*toggle on/off*` just above them to un-comment them and
   make them active.
 *     ```
       /*-either-*/
       /* tell database to recognize and use http://domain.com
       /** @ near top of theme functions.php /*toggle on/off*
       update_option('siteurl','http://domain.com');
       update_option('home','http://domain.com');
       /*-or-*/
       /* tell database to recognize and use http://www.domain.com
       /** @ near top of theme/functions.php /*toggle on/off*
       update_option('siteurl','http://www.domain.com');
       update_option('home','http://www.domain.com');
       /*-end-*/
       ```
   
 *  Thread Starter [bayworth](https://wordpress.org/support/users/bayworth/)
 * (@bayworth)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-94/#post-6502438)
 * Thank you for this help. I am trying to plough through now. However, I am alrady
   stuck at your comment about table-prefix.I dont seem to have any such information.
   should this be a table in the databases. I should have added that I have the 
   woocommerce plugin installed. So my database contains about 19 tables labelled
   things like Ucomments, Uoptions, Ulinks etc Is the table-prefix data you refer
   to tucked away in one of these tables or should I be looking elsehwere?
 *  [leejosepho](https://wordpress.org/support/users/leejosepho/)
 * (@leejosepho)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-94/#post-6502454)
 * > my database contains about 19 tables labelled things like Ucomments, Uoptions,
   > Ulinks etc
 * The table prefix is the part immediately preceding _Ucomments, _Uoptions, _Ulinks,
   _etc. The WordPress default would look something like this:
 * wp_Ucomments
    wp_Uoptions wp_Ulinks wp_etc
 * So, you either have two sets of tables (two “databases”) in one server database(
   and there is nothing wrong with that as long as each site has its own SQL user)
   or else you have two databases at the server and with each database having a 
   prefix that might or might not be the same as the other.
 * database name + table_prefix + table name =
    DB1name_prefix1_tables DB2name_prefix2_tables
 * Then as entered in wp-config.php (minus table names):
 *     ```
       define('DB_NAME', 'database_name_here');
   
       define('DB_USER', 'username_here');
   
       define('DB_PASSWORD', 'password_here');
   
       $table_prefix  = 'wp_';
       ```
   
 *  Thread Starter [bayworth](https://wordpress.org/support/users/bayworth/)
 * (@bayworth)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-94/#post-6502469)
 * OK Lee I think I am drifting into choppy waters and might be making things worse.
   Firstly I have to admit an ID10T error. Yes I was being stupid. When I took your
   advice and jotted down each database name and user information next to each I
   realised I had missed a “o” out of the user information and had assumed it was
   the same as the DB name. Secondly I was loading my modified wp-config file to
   the wrong folder and hence why my changes were doing nothing. I have since go
   things round the right way and that seems to have fixed it. Well its working.
   
   However, following on from you comment I am not sure if I am making things worse
   and I am still a little confused about the password entry. Using my real information
   now as an example. My original database was labelled db589834258 under this database
   I had tables all starting with ZctfvVr and then followed by Ucomments etc. So
   I assume from your comment that the ZctfvVr bit is the table prefix. I then have
   my second database (new) which is called db590009115. However, this seems to 
   contain more tables. It has some tables labelled wNvQHsBcomments, Boptions etc.
   plus it has a list of tables labelled ZctfvVrUcomments etc. I am assuming the
   latter tables are were created when I imported the old database and the first
   ones were created whent he database was first setup. I suppose my question now
   is, should I have both sets of tables present? Do I need to delete some or am
   I creating a future problem? Finally I have a comment on the password issue in
   wp-config. I ammended my database password via the phpadmin panel. I then updated
   the wp-config to reflect the same password and as I said it seems to work fine.
   But the password is no longer encrypted in the wp-config. Also the password I
   set on the database does not seem to reflect the password set on the wp-login
   panel that I access via the website. So it seems there are multiple passwords
   in use which is all very confusing.
 *  [leejosepho](https://wordpress.org/support/users/leejosepho/)
 * (@leejosepho)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-94/#post-6502480)
 * > My original database was labelled db589834258 under this database I had tables
   > all starting with ZctfvVr and then followed by Ucomments etc. So I assume from
   > your comment that the ZctfvVr bit is the table prefix.
 * Yes, but I have no idea how the ‘U’ came to be at the beginning of ‘comments’…
   and please forgive me for not questioning that earlier since that is not how 
   WordPress typically does things.
 * > my second database…has some tables labelled wNvQHsBcomments, Boptions etc. 
   > plus it has a list of tables labelled ZctfvVrUcomments etc.
 * Do you have any idea at all about how those table names came to be anything other
   than ‘_comments’, ‘_options’. _etc? It sounds to me like either you or someone
   had done some editing outside of phpMyAdmin or else whatever you had used for
   export/download/upload/import has grossly corrupted things.
 * > I suppose my question now is, should I have both sets of tables present? Do
   > I need to delete some or am I creating a future problem?
 * You can have more than one set of tables (tables for more than one site) in the
   same database container (database name) at the server, but I do not do that without
   first having a specific need or reason such as sharing users.
 * > …the password is no longer encrypted in the wp-config.
 * It never was, but it might have appeared to be. Passwords are only encrypted 
   inside the actual database where site user credentials are stored.
 * > Also the password I set on the database does not seem to reflect the password
   > set on the wp-login panel that I access via the website. So it seems there 
   > are multiple passwords in use which is all very confusing.
 * Yes, there are different passwords for different things, and they need to be 
   that way as part of overall security:
 * Server login at host: hosting username
    Server login at host: hosting password
   note: Some hosts have multiple passwords for doing different things at the server.
 * SQL user at server: SQL username (unique for each site)
    SQL user at server: 
   SQL password
 * WordPress LogIn: username
    WordPress LogIn: password
 *  Thread Starter [bayworth](https://wordpress.org/support/users/bayworth/)
 * (@bayworth)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-94/#post-6502490)
 * Thanks for this.Regarding the Ucomments query you made. In my first database 
   I just used the Worpress install via my hosting provider (oneandone) so the first
   set of tables were completely automatically created with U in front. I did install
   the Woocommerce plugin so maybe its due to this.
 *  Thread Starter [bayworth](https://wordpress.org/support/users/bayworth/)
 * (@bayworth)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-94/#post-6502494)
 * Regarding your comment about database export etc. I used the phpadmin function
   to export the database. I used the same function to import the old one into the
   new database.
 *  [leejosepho](https://wordpress.org/support/users/leejosepho/)
 * (@leejosepho)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-94/#post-6502502)
 * > the first set of tables were completely automatically created with U in front.
   > I did install the Woocommerce plugin so maybe its due to this.
 * Yes, possibly, but I know nothing at all about WooCommerce and now it might deal
   with a database.
 * > I used the phpadmin function to export the database. I used the same function
   > to import the old one into the new database.
 * Do you have things working now or do you still have troubles?
 *  [exdesign](https://wordpress.org/support/users/exdesign/)
 * (@exdesign)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-94/#post-6502650)
 * Recently 1and1 changed their databases from 5.1 to 5.5 and it has intermittent
   issues that say there’s an error establishing a connection with the database.
   Look to see if your database is 5.5. It will say it next to it on the My SQL 
   Databases area of your account.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Error Establishing Database Connection’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [login](https://wordpress.org/support/topic-tag/login/)
 * [moving](https://wordpress.org/support/topic-tag/moving/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 3 participants
 * Last reply from: [exdesign](https://wordpress.org/support/users/exdesign/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/error-establishing-database-connection-94/#post-6502650)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
