John Davidson

mysql - Laravel is not connecting to the php myadmin database

0 comments
Message:


I am trying to connect laravel application to php myadmin.


When DB_HOST=127.0.0.1 in my .env file


SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `sessions` where `id` = EO901DpTx4qUrgxMniyykEu84HrJGQESns0ySzlx limit 1)


and when DB_HOST=localhost in my .env file


SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `sessions` where `id` = WYha9n6qWtwN0YcAACdydQSgyHeMc1PcID2Mb6Ns limit 1)


What I’ve tried:



  • changing the DB_HOST to localhost and 127.0.0.1 (most common
    answer online, no succes)

  • making sure SQL is running

  • clearing cachefor php artisan config:clear


my .env file is as follows


DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=haydar
DB_USERNAME=root
DB_PASSWORD=

my data.php file is as follows


            'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'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' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],


My Answer:
'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,
],

Make sure that your MySQL server is running and that the credentials in your .env file match the credentials for your phpMyAdmin database. Also, check if there are any firewall settings blocking the connection. If the issue persists, you may want to try using the IP address of your MySQL server instead of 'localhost' or '127.0.0.1'.

Rate this post

3 of 5 based on 9295 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us