2

Hi I am trying to set up craft CMS with composer. I am using MAMP on a mac and I just cannot get it to connect. I get this error even though I know the password is correct.

failed: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

I have tried setting up a new user with new password and ensure full access privileges are set up on that database but I get the same error. I have tried setting up a separate host but when I try and run the Craft CMS set up with that I get this error:

Testing database credentials ... failed: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known

Any help with this would be much appreciated as I've wrestled with it all day now. Thanks.

1 Answer 1

1

I am also using MAMP on a Mac, and had similar issues first setting up. There are a few things to check.

Under your host settings, use the traditional ports instead of MAMP's custom ports, and set your servers to run as your local Mac user.

enter image description here

Then on the MySQL settings window, make sure to allow incoming connections, and check the box to include it in "group start". You can also confirm it's on the right port, here, in the upper right.

(I also suggest using MAMP to change the MySQL root user password - I set it to root which is the MAMP default.)

enter image description here

Lastly, make sure you and MAMP are both using the same MySQL! If you have it installed via homebrew as well, then you might not be running the same as MAMP does. On the command line, you can use the one in MAMP via:

/Applications/MAMP/Library/bin/mysql -h localhost ...

Assuming you're using the defaults, first, Run ./craft setup and use the following:

Database driver: mysql
Database server: localhost
Database port: 3306
Database username: root
Database password: root

There are also custom backup and restore commands that work better for MAMP and Craft CMS which you might find helpful.

3
  • 1
    Thanks for a really great and detailed answer! That was very helpful and you were right. I had mysql set up via Homebrew. Once I deleted that things got a whole lot easier.
    – cannon303
    Commented Apr 18, 2021 at 23:27
  • Also I didn't have Allow Network access to MySQL ticked in MAMP which you had in your screenshot which was the final hurdle.
    – cannon303
    Commented Apr 18, 2021 at 23:29
  • I'm really glad I was able to help! <3 Commented Apr 20, 2021 at 16:17

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.