0

I keep getting these errors when I run the command php artisan migrate

In Connection.php line 664:

  SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_s  
  chema.tables where table_schema = homestead and table_name = migrations)     

In Connector.php line 67:

  SQLSTATE[HY000] [2002] Connection refused 

My.env file contains this:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret 

My database.php file contains this:

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

Any ideas what's wrong? I've been looking for help online but none of them have worked so far.

fredjohnson
  • 187
  • 2
  • 10
  • 18
  • "Connection refused" means there's no MySQL server running on `localhost`. – Barmar Jan 26 '18 at 03:23
  • Try using `localhost` instead of an IP address. Then it should use a Unix-domain socket instead of trying to use the network. – Barmar Jan 26 '18 at 03:23
  • Yeah chances are the MySQL user has permissions for access using `localhost` and not `127.0.0.1`. –  Jan 26 '18 at 03:24
  • Hi, I used localhost instead of 127.0.0.1 but I'm still getting the same error. – fredjohnson Jan 26 '18 at 03:29

1 Answers1

0

try alternative,

  1. create new database in phpmyadmin or sqlyog or whichever you have.
  2. set the credentials and database name as per that.
  3. then fire composer update followed by composer dump-autoload and php artisan config:cache
  4. and then check again if its working

I hope this will solve your problem.

Rahul
  • 18,271
  • 7
  • 41
  • 60
  • Hi, I opened phpMyAdmin but whenever I try to login it gives me the error saying `#2002 - No such file or directory — The server is not responding (or the local server's socket is not correctly configured).` – fredjohnson Jan 26 '18 at 03:31
  • once check with this [link](https://stackoverflow.com/questions/1676688/php-mysql-connection-not-working-2002-no-such-file-or-directory) for your problem – Rahul Jan 26 '18 at 03:33