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

Balázs Szente
Balázs Szente
1,003 Points

Artisan migrate PDOException

On my Windows PC, when I try to run php artisan migrate it gives the following result: [PDOException] SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

3 Answers

Tricky one! I've searched around your error message and a lot of the simpler fixes areL

  • Make sure the mysql server is running
  • If you're using XXAMP / WAMP make sure it's all green for go

[This poster]9http://stackoverflow.com/questions/12010524/sqlstatehy000-2002-error "Stack Overflow") resolved their issue by making sure they passed in data for all the columns.. but this seems kind of redundant because what if your columns aren't 'required'!

In your app configuration files, you can try changing localhost to 127.0.0.1 - this can be quite a good fix for a number of database connection problems.

this poster resolved the issue by making sure the database username and password details were correct.

It looks like you're playing with laravel. Can you post your app > config > database.php?

If you're working locally, and have your application set for local work, maybe also give us your app > config > local > database.php

We only want the mysql connection section of the array - it should look like this:

<?php

        'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'odot',
            'username'  => 'homestead',
            'password'  => 'secret',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ),
Balázs Szente
Balázs Szente
1,003 Points

When I try to migrate the Laravel database I got the notice, "Application In Production". Do you really wish to run this command? Then I press "y", and get the mentioned error.

My app is in localhost. I tried to overwrite the host to 127.0.0.1, but that didn't helped. I watched the mysql error log, and found no problem. This means could be mean that the problem is the bad config. Tomorrow afternoon I will try to access the database from windows console. I tried mysql workbench and that could connect from outside of virtual box with the host 127.0.0.1.

My app > local > config > local > database.php contains these lines to setup mysql:

<?php

'mysql' => array(
            'driver'    => 'mysql',
            'host'      => '127.0.0.1',
            'database'  => 'odot',
            'username'  => 'homestead',
            'password'  => 'secret',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            // ,'port'          => 33060
        ),

i've just edited your markup - you need some returns to make it display properly :)

Balázs Szente
Balázs Szente
1,003 Points

Thanks for the edit. I still have the problem. With MySQL workbench I can connect, and the page can connect too, but when I run the

php artisan migrate

I get the following message:

[PDOException] SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.