Jump to content

Using DDev - Database connection information did not work.


Greg Lumley
 Share

Recommended Posts

Hi, I realise this is a little sideways. I've just started using ddev, or I'm trying to at least, it really is a fantastic solution from what I can see.

I've scoured the Internet and have yet to come across something that explains why it's not connecting. 

Even with a fresh Processwire install, I get a DB connection error. 

DBname: db
DBuser: root
DBpass: root
DBhost: localhost
DBport: 3306
 

Quote

Database connection information did not work.
 SQLSTATE[HY000] [2002] No such file or directory

 



Loading PhpMyadmin shows the DB exists and is working perfectly. 
 

ddev describe gives me all the information:



 db       │ OK   │ InDocker: db:3306                                      │ mariadb:10.4       │
│          │      │ Host: 127.0.0.1:32781                                  │ User/Pass: 'db/db' │
│          │      │                                                        │ or 'root/root'

Is there something else I should be doing when trying to connect? 

Thank you. 

Link to comment
Share on other sites

I found the problem, unless I missed something, it's not obvious. 

The host in ddev is "db" not localhost 

DBname: db
DBuser: root or db
DBpass: root or db
DBhost: db
DBport: 3306

 

Hopefully, this saves someone some Internet Scouring time. ?
 

  • Like 2
Link to comment
Share on other sites

Hi @Greg Lumley

That's correct - you need to use "db" as the DBHost in the site/config.php file for ddev because MySQL/Maria is running in a separate container called "db" in the ddev stack. Both the webserver container and database container are attached to a dedicated virtual network when you bring up your stack. Docker's DNS resolver automatically makes the internal network IP of the database server available to other containers on the same virtual network using the container name - hence the need for "db" in the config file.

In docker stacks where both the webserver and MySQL/Maria DB were running in the same container then you could use "127.0.0.1" or "localhost" as the DBHost - but that's not the case for ddev.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...