0
votes

I have a problem with my Laravel project. I started it a few hours ago but I'm stuck with an SQL error :

SQLSTATE[HY000] [2002] Connection refused

I've searched for hours now and I only found it would be wrong password or wrong port but I checked and it's fine for me.

Here's the .env file :

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3302
DB_DATABASE=test_technique
DB_USERNAME=root
DB_PASSWORD=

Here's the .env.example file :

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3302
DB_DATABASE=test_technique
DB_USERNAME=root
DB_PASSWORD=

And here's the database.php :

'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3302'),
        'database' => env('DB_DATABASE', 'test_technique'),
        'username' => env('DB_USERNAME', 'root'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],
    ],

And to check the port of mysql :

Test for TCP
Your port 3302 is used by a processus with PID = 2292
The processus of PID 2292 is 'mysqld.exe' Session: Services
The service of PID 2292 for 'mysqld.exe' is 'N/A'
N/A means that there are no service related to PID 2292
Processus 'mysqld.exe' is launched by service 'wampmysqld64' with PID 5048

Test for TCPv6
Your port 3302 is used by a processus with PID = 2292
The processus of PID 2292 is 'mysqld.exe' Session: Services
The service of PID 2292 for 'mysqld.exe' is 'N/A'
N/A means that there are no service related to PID 2292
Processus 'mysqld.exe' is launched by service 'wampmysqld64' with PID 5048

I've never changed the USERNAME and PASSWORD in mysql so I don't know why there's this error

P.S : In another site, when I use PDO like this, it works :

new PDO("mysql:host=localhost:3302;dbname=test_technique;charset=utf8", "root", "",array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
1
Hmmm. 3306, not 3302, is the default port for MySQL It might help us help you if you edit your question to explain your particular setup a bit more completely, - O. Jones
I know but my 3306 is already used so I switched to 3302 for mysql. - Chewbaccademy
Make sure that you can connect to mysql on the command line with port 3302. mysql -u root --port=3302. If you cannot, then you'll need to change the configuration of mysql. Though I'm curious what's running on 3306 that isn't mysql. - aynber

1 Answers

1
votes

The default port for MySQL is 3306 not 3302 you must use like this unless you have changed the port in php.ini

DB_PORT = 3306

Run this command

php artisan config:clear

And instead of using

php artisan serve 

Use

 php -S 127.0.0.1:8000 -t public/

This might help because if you use artisan serve and make changes to env you must kill the serve and run again.