Behat init.php gives error dbconnectionfailed

Behat init.php gives error dbconnectionfailed

by Joshua Todd Cowper -
Number of replies: 2
Bildo de Core developers Bildo de Testers

Hi there,

I'm not experienced with Behat but am trying to follow the Quick start instructions in the Acceptance testing article in the dev docs as best I can.

I first tried to run through these steps using AMPPS on my Mac but ran into the dbconnectionfailed error I'll describe in a moment, so to exclude anything related to my confuguration, I opened up a VM running a fresh install of OS X 10.9.4 and did the following:

  1. Installed Firefox
  2. Installed JDK 8u82
  3. Installed Moodle4Mac 3.0.3
  4. Launched MAMP and logged into Moodle to confirm the installation was working
  5. Followed the Quick start instructions from dev docs
    1. Opened a CLI
    2. cd /Applications/MAMP/htdocs/moodle30
    3. Added these lines to config.php:
      $CFG->behat_prefix = 'b_';
      $CFG->behat_dataroot = '/Applications/MAMP/data/behat30';
      $CFG->behat_wwwroot = 'http://127.0.0.1:8888/moodle30'; // must be different from wwwroot
    4. Skipped step 4 as it seemed appropriate according to danpoltawski's simplified instructions
    5. php admin/tool/behat/cli/init.php
      This went through the process of installing everything, an OS X update prompt came up to install command line tools which I accepted
      Then, I get the same dbconnectionfailed error I received in my earlier testing. I ran the init.php command again and this is the full output including the error:
Joshuas-MacBook-Pro:moodle30 jtc$ php admin/tool/behat/cli/init.php
You are already using composer version 1.0.3 (stable channel).
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
Default exception handler: <p>Error: Database connection failed</p>
<p>It is possible that the database is overloaded or otherwise not running properly.</p>
<p>The site administrator should also check that the database details have been correctly specified in config.php</p> Debug: No such file or directory
Error code: dbconnectionfailed
* line 449 of /lib/dml/mysqli_native_moodle_database.php: dml_connection_exception thrown
* line 344 of /lib/dmllib.php: call to mysqli_native_moodle_database->connect()
* line 615 of /lib/setup.php: call to setup_DB()
* line 112 of /admin/tool/behat/cli/util_single_run.php: call to require()

!!! <p>Error: Database connection failed</p>
<p>It is possible that the database is overloaded or otherwise not running properly.</p>
<p>The site administrator should also check that the database details have been correctly specified in config.php</p> !!!

Debug info: No such file or directory
Error code: dbconnectionfailed
Stack trace: * line 449 of /lib/dml/mysqli_native_moodle_database.php: dml_connection_exception thrown
* line 344 of /lib/dmllib.php: call to mysqli_native_moodle_database->connect()
* line 615 of /lib/setup.php: call to setup_DB()
* line 112 of /admin/tool/behat/cli/util_single_run.php: call to require()

The actual Moodle installation has no issues with the database as evidenced by the fact I can login, see my user details, etc without throwing an error.

Any guidance on where to start troubleshooting this would be much appreciated! Thanks.

Average of ratings: -
In reply to Joshua Todd Cowper

Re: Behat init.php gives error dbconnectionfailed

by Tim Hunt -
Bildo de Core developers Bildo de Documentation writers Bildo de Particularly helpful Moodlers Bildo de Peer reviewers Bildo de Plugin developers

One way to debug this:

Can you work out what details Moodle running as Behat is trying to use to connect to the database? Go into moodle_database, or mysql_native_moodle_database, or whichever class is being used. Find the connect method, and add some print_r statements to output the values Moodle is actually using.

Once you have found that out, try to connect to MySQL yourself, from the command line, using that username, password, etc.

Note, MySQL permissions can depend on where you are trying to connect from (This bit http://dev.mysql.com/doc/refman/5.7/en/connection-access.html). It might be that, but I am just making a wild guess.

In reply to Tim Hunt

SOLVED: Behat init.php gives error dbconnectionfailed

by Joshua Todd Cowper -
Bildo de Core developers Bildo de Testers

Thanks Tim for taking the time to help. The SQL user details being used all seemed in order, so I decided it was time to try again using Ubuntu and the Bitnami stack this time.

I got very similar output but with a much more helpful debug info:

Can't connect to local MySQL server through socket '/dev/null' (111)

This suggestion of changing CFG->dbhost to 127.0.0.1 instead of localhost at least let me move on from this error to a bunch of other ones, so I gave the same trick a try on my original Mac/AMPPS config and the Behat tests are now running.

Average of ratings:Useful (1)