• Hi,

    I have just migrated my site to a new hosting package with my provider. Therefor I needed to migrate the site and the database and now I can’t connect to my database. I get ‘Error establishing database connection’. Also if I try to logon via wp-admin. I also did a check with a check.php file to connect to my database. This results in a blanck page. I used the following script;
    <?php
    $link = mysql_connect(‘DB Host’, ‘DB username’, ‘DB password’);
    if (!$link) {
    die(‘Could not connect: ‘ . mysql_error());
    echo ‘Connected successfully’;
    mysql_close($link);
    ?>

    I am really desperate ??

    Kind regards,
    Stephen

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hey there!
    Since you are transferring a site to another hosting account, I suppose you have exported your database from the previous host in a .sql file. Usually, when transferring a site, you would need to create a new database, new DB user and password, where to import your .sql file.
    If you are using Cpanel in your new hosting account, you can create a new DB, new DB user and DB password in Cpanel->MySQL Databases, as well as to add that new user to the new DB. Then you will need to import the .sql file of your DB into that newly created DB from your Cpanel->PHP MyAdmin-> click on new DB->Import button.
    Finally, you will need to connect your DB to your php script. That is done from your Cpanel->File manager-> your site folder/wp-config.php . In there you will need to replace DB name, DB user and DB password in the relevant lines with your newly created ones ( the DB host line should be localhost).

    I hope this information will be useful to you and will help you connect your database.
    Best regards ??

    Thread Starter stephenley

    (@stephenley)

    Hi Vladinka,
    Thanks for you respons. I use PHPmyadmin to manage the database. This is supported by the hosting firm. If I do what you describe;
    – Create a new database
    – Import the SQL file into the new database etc.
    Then the SQL file is not imported but a new database is automaticlly created. So to be precise;
    – I created a DB named SMD2017
    – Imported the SQL file which I exported from the old environment and has the name md78753db361567.
    – Now PHPadmin creates a new database instance named md78753db361567
    And this results in the same, no connection to DB.

    Any suggestions?

    Is md78753db361567 the prefix of your database tables inside the newly created DB ( shown in PHPMyAdmin) ?
    And also have you replaced the existing DB name, DB user and DB password in your wp-config.php file with the new ones? Having in mind that the full DB name and DB user should be placed in the wp-config.php – for example cpuser_SMD2017 .

    Thread Starter stephenley

    (@stephenley)

    Hi,
    In PHPMyadmin after the import I see two DB instances. The one I created (SMD2017) and the one PHPMyadmin created after the import. What I do is click on the SMD2017 instance and select import. So it should import in the SMD2017 DB but instead it creates another DB named md78753db361567. The SMD2017 instance is empty and the md78753db361567 is filled with tables which is correct.
    I changed the credentials in the config file, but not with cpuser before the user name.

    Thread Starter stephenley

    (@stephenley)

    Sorry posted to fast. I think the issue is not with connecting with the DB itself but with the DB host. How can I check if I can connect with the host?

    Thread Starter stephenley

    (@stephenley)

    If I look in the log files I see;

    [Mon Jan 09 13:02:09.836364 2017] [:error] [pid 12834] [client 69.162.124.235:49818] PHP Parse error: syntax error, unexpected ‘DB_USER’ (T_STRING) in /home/public/sites/www.servicemanagerdag.nl/wp-config.php on line 26, referer: https://www.servicemanagerdag.nl/

    This suggest that the DB_USER is not correct. But I don’t see anything wrong. The user I created is SMD2017 and this is also what I use. If I change it to the dbm user, issue is still the same.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Cannot connect to DB’ is closed to new replies.