pjuakiy's avatar

Mysql SQLSTATE[HY000] [2002] Connection refused

Hi,

I freshly installed laravel 10. Running on WSL-windows-docker.

My database settings are using mysql.

My artisan commands work (php artisan migrate:fresh; php artisan db:seed;), but when I try it on the localhost-webpage, it fails. Error shown is

SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select * from....

Docker-mysql log shows it is running

2023-06-22 21:21:32 example-app-mysql-1         | 2023-06-22T13:21:32.653665Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-06-22 21:21:32 example-app-mysql-1         | 2023-06-22T13:21:32.771970Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-06-22 21:21:33 example-app-mysql-1         | 2023-06-22T13:21:33.030321Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-06-22 21:21:33 example-app-mysql-1         | 2023-06-22T13:21:33.030374Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-06-22 21:21:33 example-app-mysql-1         | 2023-06-22T13:21:33.059246Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2023-06-22 21:21:33 example-app-mysql-1         | 2023-06-22T13:21:33.059405Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.32'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.

When I switch it to use sqlite, both artisan and webpage works.

Any ideas ?

0 likes
3 replies
jlrdw's avatar

Also you can just download the zip versions of Apache or Nginx, Mariadb, and php and set them up. Only takes about 5 minutes.

However, setup the first time until you learn the setups does have a small learning curve. But their sites have instructions.

If you do this, save the instructions in a text file for next time.

I just make my own custom server setups.

Edit:

Your error may be because Mysql is offline or you have a wrong connection string setup.

1 like
pjuakiy's avatar

seems there was something wrong in my sail/docker. Had to clear everything up and re-install.

These commands worked for me.

docker-compose down --volumes;
composer remove laravel/sail ;  composer require laravel/sail --dev  ; php artisan sail:install  ;
./vendor/bin/sail build  ; ./vendor/bin/sail up --build -d;
2 likes

Please or to participate in this conversation.