0

I was trying to set up a Laravel project but whenever I hit php artisan migrate it results in this error

   Illuminate\Database\QueryException 

  SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = src and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
    674▕         // If an exception occurs when attempting to run a query, we'll format the error
    675▕         // message to include the bindings with SQL, which will make this exception a
    676▕         // lot more helpful to the developer instead of just the database's errors.
    677▕         catch (Exception $e) {
  ➜ 678▕             throw new QueryException(
    679▕                 $query, $this->prepareBindings($bindings), $e
    680▕             );
    681▕         }
    682▕ 

      +36 vendor frames 
  37  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

I am using laravel/framework:^8.12 in WSL Ubuntu 20.04LTS.I know this is a really common problem ,but none of the solution worked for me .

my .env file

APP_NAME=Laravel APP_ENV=local APP_KEY= APP_DEBUG=true APP_URL=http://localhost

LOG_CHANNEL=stack LOG_LEVEL=debug

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=src DB_USERNAME=root DB_PASSWORD=

BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379

MAIL_MAILER=smtp MAIL_HOST=mailhog MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET=

PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

tensorMan
  • 17
  • 6
  • can you access the database with those connection details outside of Laravel? Using `mysql-client` or a GUI application like TablePlus, dbeaver etc.. – Galironfydar Mar 09 '21 at 16:02
  • 1
    If you have MySQL installed on WSL. Open a terminal window and run the following: `mysql -h 127.0.0.1 -u root -p` (type password in when prompted) – Galironfydar Mar 09 '21 at 16:05
  • @Galironfydar I have installed TablePlus Can you provide me a link or explain how to connect both these two,individual steps would be great,I have never done anything like this before.Thanks for the reply – tensorMan Mar 09 '21 at 16:06
  • @Galironfydar that results in ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111) – tensorMan Mar 09 '21 at 16:08
  • Do you have a MySQL server running? – Galironfydar Mar 09 '21 at 16:09
  • @Galironfydar I have previously worked in a django project there I didnt do anything like this so i thought i dont need to start MySQL server running ? What are the steps for running MySQL server – tensorMan Mar 09 '21 at 16:11
  • 1
    Okay, seems like you don't have a MySQL server installed. You can follow this guide on [Installing MySQL](https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04) within WSL. Once you've configured it, it should be a case of using the correct connection details. – Galironfydar Mar 09 '21 at 16:13
  • @Galironfydar Thanks for your reply it helped me a lot .I faced a few more errors but I did solve it. Mentioned article was specific to Ubuntu 20.04 LTS ,but there were some issues with wsl2 ,but it helped me. – tensorMan Mar 11 '21 at 14:19

0 Answers0