Please show your database.php
Illuminate\Database\QueryException SQLSTATE[HY000] [2002] No such file or directory
Hello, am having this error
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] No such file or directory
evertime i try to run my project I recently moved from windows to linux everything was working fine on my windows machine but now it shows the error above
things I've tried to do
run composer update | didn't solve the problem
run composer require doctrine/dbal | also didn't work
run apt install php-mysql | also didn't work
and run php -m | and it listed pdo
am running php v 7.4.3
<?php
use Illuminate\Support\Str;
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'mysql' => [
'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' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer body of commands than a typical key-value system
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
],
'default' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],
'cache' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
],
],
];
Try cleaning up your mysql definition. I assume you aren't using sockets on your Linux machine
'mysql' => [
'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', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
],
If that works, you can rollback and try testing one line at a time (my bet is that it is the socket that is breaking it)
did so and cleared the cache till the same problem
Can you show the lines you have for db in your env file?
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=ovongames
DB_USERNAME=root
DB_PASSWORD=
Looks fine
Can you check if there is a config.php somewhere in /bootstrap
If there is, your config is still cached. Run php artisan config:clear or remove it manually
no there only cache folder and app.php file
everthing looks fine to me to the but nothing works I've had this problem since yesterday and I've been googling yet since then didn't find anything to help me fix the issue.
am using xampp running it through sudo /opt/lampp/lampp start and before running this code i run sudod /etc/init.p/apache2 stop to stop the apache2 to and then doing lampp start and it give me success mysql server opended and apache opend and tried to open phpmyadmin it opened fine and when i route to a file that doesn't get data from the db also works fine the db name in .env file is correct checked that like million time, am out of ideas
I have never tried xampp on Linux (I use Ubuntu myself). But you could give docker a try
Can you execute a query okay in phpmyadmin. Also clear your bootstrap cache folders.
yes tried the select and it worked fine
I've download a fresh laravel app and used one of the controllers at the one that didn't work the same controller and it worked fine?
Try copying database.php over
Oh just curious. Did you setup a model and do migrations etc on the new project? Be sure to do so, otherwise you can't really compare
Nope i didn't setup any models or migration i used DB to retrieve data from database in the new project and tried to copy database.php to the old one and also didn't work hill i even replaced the .env file to but also didn't work, so I've decided to move my files to the new project
Try copying a directory from app one at the time from the old project to the new and see if it breaks
Sounds interesting, you mean going through every file to see what really caused the problem. Will do and let you know will be fun 🤗
Just start with a directory at the time. No need to go file by file
Please or to participate in this conversation.