I moved a site - actually copied a production site to a development region.

The site is working in the development region, including CiviCRM, but the CiviCRM cron job fails:

Jun 29 16:33:02  [info] $Fatal Error Details = Array
    [callback] => Array
            [0] => CRM_Core_Error
            [1] => handle

    [code] => -24
    [message] => DB Error: connect failed
    [mode] => 16
    [debug_info] =>  [nativecode=mysql_connect(): Access denied for user 'hostuser_drupal'@'localhost' (using password: YES)]
    [type] => DB_Error
    [user_info] =>  [nativecode=mysql_connect(): Access denied for user 'hostuser_drupal'@'localhost' (using password: YES)]
    [to_string] => [db_error: message="DB Error: connect failed" code=-24 mode=callback callback=CRM_Core_Error::handle prefix="" info=" [nativecode=mysql_connect(): Access denied for user 'hostuser_drupal'@'localhost' (using password: YES)]"]

I can log into the site as the same user that the cron job is using, and everything works. But the cron job fails, saying that the Drupal database user is denied.

There is a Drupal database and a CiviCRM database. There is a MySQL user for each database. At this point, both users have access to both databases.

Obviously the credentials in the config files are correct, since Drupal and CiviCRM work as normal in the browser. But the cron task fails as described above, whether called by cron or by using the cron URL in the browser.

Here is the cron job:

wget -O - -q -t 1 'http://somedevsite.com/sites/all/modules/civicrm/bin/cron.php?name=admin&pass=33333333333333&key=44444444444444444444444444444444'

What could be going on?

EDIT I switched the cron task to call /civicrm/bin/cli.php directly (via php) and it fails in exactly the same way.

  • 1
    Might better inform your responses if you include the cron command you're using here - make sure to remove your user/pass details when doing so :) Jun 29, 2016 at 22:47
  • Edited to add cron command.
    – GHolmes
    Jun 30, 2016 at 15:06

2 Answers 2


OK, I was being stupid. Typo in the Drupal database password in the CiviCRM config file.

Digging into civicrm/packages/DB/mysql.php and inserting some logging showed that the passwords being used for the Drupal user were just slightly different between Drupal and CiviCRM. CiviCRM was adding an extra '@' to the end.

Didn't see it before because due to the CiviCRM config file format, it was a double @ - my eye didn't see the double.

define( 'CIVICRM_UF_DSN' , 'mysql://host_drupal:123456789@@localhost/host_drupal?new_link=true' );


Commandline and webserver PHP differ in a few ways.

  • They can read different PHP configurations via php.ini
  • They may therefore have different PHP modules enabled (this doesn't seem to be the problem for you, but might cause CLI PHP to lack the mysql module)
  • CLI PHP doesn't automatically have the HTTP host populated

IMO the most likely cause is that the relocation to a dev environment has changed behaviour in the last of those, if you're using Drupal's multisite functionality. You might have addressed this for the new dev environment, but not informed the cron task of your changed config.

If so, you can probably address this by -

  • updating the cron command to use the dev URL (drush -l example.dev civicrm-cron), or
  • through Drupal's sites.php, or
  • symlink sites/example.dev => sites/example.com directory (*ew).
  • The cron job is actually calling it via URL though. I edited my question.
    – GHolmes
    Jun 30, 2016 at 15:21
  • This answer doesn't apply to your question then, sorry! Will leave it here for posterity & to ensure no-one repeats my error :) Jul 1, 2016 at 0:05

Your Answer

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

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