I am new in Laravel development.
I have updated Xampp to 7.3.11 on my Mac Mojave 10.14.6.
In Laravel project when I hit php artisan migrate command I got following error.
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from
information_schema.tables where table_schema = laravel and table_name
= migrations and table_type = ‘BASE TABLE’)
When I start Xampp service, my admin panel run on http://127.0.0.1:8080/phpmyadmin.
My working project in Laravel is also not connecting with database saying connection refused.
I tried by changing DB_Port
and DB_Host
in .env file.
I tried by clearing cache.
Any Help will be appreciated.
My .env
file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
15
Answers
Open
localhost/phpmyadmin
and find a tab calledUser accounts
.Find the
root
user and set its password in your.env
and also don’t forget to create the database namedlaravel
if it doesn’t existThen you can clear config cache
And migrate
I had the same issue. It was resolved by just restarting the local host server i.e Xampp
I had the same problem and when I applied the following operations, the problem was solved.
I’ve come across this Error too by building up a new project with Laravel running in docker-compose for development.
My solution was to compare the prebuild .env-File with the actual credentials I used for building the database container.
Especially I was using
DB_HOST=127.0.0.1
instead of the correct service name of my docker-compose setup:DB_HOST=mysql
Try this conf in .env (i’m using Laravel v7.0), it’s working for me :
Try out doing
then on your .env file specify your database and your port
then run your mysql server and run
Note: Make sure your Xammp server is perfectly fine & have already started mysql (using apache server or any server you are using) and also make sure you already created your database before running php artisan migrate Hope it works for you
Damn, I feel so stupid lol.
This is what helped me after scratching my head for hours.
Check what port your MySQL is running on and that’s the one you use in your .env file.
Make sure when you create your user that you grant all privileges for the user. If you’re still confused then ask me and ill find time to help you out. Happy coding everyone!
I had this issue, I use MAMP for MYSQL server.
It was a configuration issue that I solved by changing the port to the correct one I found in MAMP instructions, which is
8889
.So the correct configuration in my
.env
file is:Just simple step i follow and solved
open .env file
change DB_HOST = 127.0.0.1 to localhost
done
In most cases it’s an issue with the port configuration. You need to check which port your server is running on. Then you have to edit the .env file of your project. For instance if you are using mamp the port should be changed to 8889 instead of the default 3606 for laravel. The same applies to laravel 8.
I was using docker compose file. All you need to do is to expose the port of the mysql
It was actually this in my case.
Before it was
Many solutions were suggesting to change
DB_HOST
to "localhost". In my case it was just a tiny little0
inDB_PORT
.I had the same issue while running laravel and mysql within a docker container (MacOs).
I figured out that the problem was within the .env file.
the default configuration in .env was :
Some answers suggested to change DB_HOST to:
But it didn’t work for me…
After some research I found out that, while running laravel in docker, the DB_HOST expects the database service that is running in docker too, in our case the service is mysql.
So I had to change the .env to this:
I also changed the DB_HOST in config/database.php
It’s only then that everything started working fine.
I’m using laravel 8 and mysql with docker, i had the same problem i tried several solutions and none worked, i deleted my containers and volumes and nothing too, so i decided to restart my os and go into incognito mode and boomm it went smoothly so i went back for my tab that was giving error and I deleted the session cookies and boom the problem was solved, another tip is to use the database container IP using docker inspect [container–database-id] instead of DB_HOST=localhost. Sorry for the writing, I don’t speak English, I hope I helped.
Verify port:
In my case (
Windowsx64
+WSL
+php/laravel8.1
) I was able to add data source via PhPStorm/PyCharm using valid credentials butphp artisan migrate
ended up withSQLSTATE[HY000] [2002] Connection refused
error every time.I had to stop
MySql
service from XAMPP control panel and setup DB and USER viamysql-cli
after stopping services from XAMPP, do
sudo service mysql start
and then: