0

I am trying to get a local drupal environment up and running using an sql dump from a production environment. I am attempting to follow instructions from drupal's documentation.

So far, from our production server, I went ahead and ran drush sql-dump > prod_drupal_backup.sql. Then, I used scp to pull the prod_drupal_backup.sql file from the production server.

On my local machine, using MAMP, I created a database (prod_drupal, same as the database on the production server) and gave a user, admin, access to the database. I went ahead and pulled down the codebase and created a fresh Drupal instance. During this set up, I gave Drupal the admin credentials to connect to the database and had a fresh site up and running.

With a backup, I was ready to restore the database using the prod_drupal_backup.sql SQL dump file. So I went and ran /Applications/MAMP/Library/bin/mysql -uroot prod_drupal < ~/Desktop/db_backup.sql. After this completed, I checked the database via MAMP's localhost:8888/phpmyadmin. The prod_drupal database had the correct data in it. So then I went to the website (localhost:8888) and saw what I wanted, the login screen with all of our styling and everything. When I logged in using one of the accounts registered for the site, it thrown the The website encountered an unexpected error. Please try again later. error.

When I look at my MAMP sql error logs in mysql_error.log, I see errors like access denied for user 'mikesmith@localhost'. This makes zero sense because Drupal is supposed to be connecting to the database with admin, not mikesmith. The way Drupal is trying to connect to the database doesn't match what's in the settings.php file.

What am I doing wrong?

I am using MAMP Pro 5.5.1 and PHP 7.2.21, if this makes any difference.

5
  • You definitely don't have an optionally included settings.local.php with these bogus credentials in them?
    – Clive
    Oct 10, 2019 at 18:08
  • I don't think so... would that be located in sites/default/? I have also noticed that if I just type in mysql into my command line, I get the error access denied to user 'mikesmith@localhost'...
    – user96646
    Oct 10, 2019 at 18:22
  • I think what is happening is that drupal is attempting to access mysql using my active user on my Mac, instead of the user I defined in settings.php...
    – user96646
    Oct 10, 2019 at 18:32
  • 1
    It seems likely the errors in MySQL.log are unrelated to the attempts to login to Drupal. You wouldn’t even see the login page if the DB connection failed for a start :) Find the apache error log and look in there, it should have more info
    – Clive
    Oct 10, 2019 at 19:03
  • @Clive My apache error log does not report anything when I am navigated from the login page to any other location...
    – user96646
    Oct 10, 2019 at 20:58

1 Answer 1

1

Some possible solutions / debugging steps:

Check that your local settings.php file is correct by using drush status command. Do this when in the same directory as the settings.php file (or with a correctly set up site alias). You should see information about the database and drupal version. If you don't then something is wrong with your settings.

Next, Drupal uses the DB to cache things in the DB. This cached information in an SQL dump can cause a local site to crash. Some ways to possible ways to correct this are:

  • On the local site, try using the drush cc (assumed D7 per tag) on the command line.

(OR)

  • Prior to making the dump from production, clear cache (either via admin screen or drush cc).

(OR)

  • Remove the contents of any Cache_* table on the local site (keep the tables)

Another possibility is that the password encryption salt string is different between the sites. This is set in the settings.php file and should be the same on both sites.

Finally, you can always reset the local user password via drush. Two useful drush commands are:

  • drush uli --name=xxx (Gets a password reset URL.. may need to put the correct host name)

  • drush upwd [username] [new-password]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.