Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Cherry Hackney
PLUS
Cherry Hackney
Courses Plus Student 2,320 Points

Load Mamp on Windows 10 and I got a Error code 2003: Can't connect to MySQL server on 'localhost' (10061)

I have a project I'm trying to load that I did a few years ago and I get unable to connect to database server as well as Error code 2003: Can't connect to MySQL server on 'localhost' (10061)

Colin Marshall
Colin Marshall
32,861 Points

In Mamp does it say that the MySQL server is running?

Cherry Hackney
Cherry Hackney
Courses Plus Student 2,320 Points

Hi Colin, MySQL is showing a green light, not sure if that was you are referring to...

Colin Marshall
Colin Marshall
32,861 Points

Yes, that was what I was wondering. The MySQL server is definitely running, so that probably means the project might be looking at the wrong port #. Can you verify that your project and MAMP are using the same port # for the database?

Cherry Hackney
Cherry Hackney
Courses Plus Student 2,320 Points

sure, how do I verify what port my project is using?

Colin Marshall
Colin Marshall
32,861 Points

Wherever the database connection is made in the code. Is this project PHP based?

1 Answer

Hola,

It just sounds like some of your connection details are incorrect, hopefully an easy fix.

Can you open up MAMP and go to preferences > ports and tell us what you see?

Can you then go wherever you're initialising the connection in your code - you don't need to tell us the username or password (although make sure they are correct!) - but we will need to know the information you've used to make the connection.

Tom

Cherry Hackney
Cherry Hackney
Courses Plus Student 2,320 Points

Hi Tom, I'm using ports 8888 for Apache and 8889 for MySQL port. After you mention about username and password, where can I find that in my connection so I can check if my code is looking at the right thing?

Hey Cherry,

I'm tempted to say that your credentials are okay (for now) because the error you have is regarding the connection. I.e. it's not actually getting as far as checking your credentials because you're not even finding the database.

Because you have MAMP setup, you should be able to use phpmyadmin.

  • Head to http://localhost:8888/MAMP/?language=English (the MAMP start page)
  • From the top nav, select Tools > phpmyadmin - This will open a new page
  • In the left sidebar of phpMyAdmin, click on 'mysql' to open the mysql database.
  • You should see a list of tables. Click the last table 'user'.

Alright! So this is where all your mysql users live. If you haven't played around with users, you'll see a user called 'root'. It might have a password - this may need changing later - but for now, try password of 'root' or 'password'.

If the password is wrong, you'll get back an error like 'root@localhost cannot connect to the database'.

If you've created a new user specifically for the project, you should know both the username and password already.

Make sure that you're host is either '127.0.0.1' or 'localhost' and the port is 8889.