This question already has answers here:
PDOException SQLSTATE[HY000] [2002] No such file or directory
(37 answers)
Closed last month.
Everything was fine until I changed my computer. I'm trying to migrate my database with php artisan migrate but I get this error
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = grain and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
708▕ // If an exception occurs when attempting to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e
714▕ );
715▕ }
716▕ }
+33 vendor frames
34 artisan:35
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Any attempt to interact with the database gives me the same error
this is my .env configuration
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=grain
DB_USERNAME=root
DB_PASSWORD=
The problem was because on my old pc I was using MAMP and now I'm using XAMPP so in the database.php file the unix_socket path was wrong.
So go to your my.cnf file and search the socket path then make sur that the socket path is the same as the unix_socket path in your database.php file
Related
When I try php artisan migrate in MacOS terminal, it shows the following -
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = project and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:759
755▕ // If an exception occurs when attempting to run a query, we'll format the error
756▕ // message to include the bindings with SQL, which will make this exception a
757▕ // lot more helpful to the developer instead of just the database's errors.
758▕ catch (Exception $e) {
➜ 759▕ throw new QueryException(
760▕ $query, $this->prepareBindings($bindings), $e
761▕ );
762▕ }
763▕ }
+36 vendor frames
37 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
I have tried
php artisan config:clear
php artisan migrate:install
but it's still showing the same message.
Check .env file. In my case, I had to change DB_PORT from 3307 to 3306 (check what's your port)
When I run the php artisan migrate command, I get the following error:
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = uploadify and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:703
699▕ // If an exception occurs when attempting to run a query, we'll format the error
700▕ // message to include the bindings with SQL, which will make this exception a
701▕ // lot more helpful to the developer instead of just the database's errors.
702▕ catch (Exception $e) {
➜ 703▕ throw new QueryException(
704▕ $query, $this->prepareBindings($bindings), $e
705▕ );
706▕ }
707▕ }
+36 vendor frames
37 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
Also, MySQL server is running and I can connect to it using the credentials provided in the .env file. Is this somehow related to Sail?
If so, how can I tell my Laravel application to use the local machine environment instead of the Sail?
Ok, there was a typo in .env for DB_HOST and I didn't notice it. Changing it back to localhost solved my problem.
This question already has answers here:
SQLSTATE[HY000] [2002] Connection refused within Laravel homestead
(31 answers)
PDOException SQLSTATE[HY000] [2002] No such file or directory
(37 answers)
Closed 1 year ago.
I'm having issues connecting to a docker instance of MySQL through Laravel. I've found that by using Tinker, I can connect successfully to the database. e.g, with Tinker, if I run
DB::select("select * from users;");
I'm able to get results. However, if I make a route
Route::post('/sql', function(Request $request){
return DB::select('select * from appointments;')->get();
});
and hit it through PostMan, I get back
"message": "SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `users` where `users`.`id` = 1 limit 1)",
I currently have the .env file set with
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test_project
DB_USERNAME=root
DB_PASSWORD=password
I've read that many people have trouble with using 127.0.0.1, but I've found that when I switch the DB_HOST to localhost, tinker doesn't even successfully connect. Instead, I get
Illuminate/Database/QueryException with message 'SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from users;)'
I've already tried
php artisan route:clear
php artisan config:clear
php artisan cache:clear
But I cannot get this to work. Any help or insight is greatly appreciated!
I am working on my Mac and i am trying to connect to database as shown in the env file i have mention the db name but i still getting this error on my laravel project. i have tried it on core php project it work but i get this error while connecting laravel project to database.
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = cart and table_name = migrations and table_type = 'BASE TABLE') at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
try this
php artisan config:clear
and then
php artisan migrate
that if you are sure the database already exists
I get this type of exception in all my Laravel projects.
Illuminate\Database\QueryException
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = orchid and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
+34 vendor frames
35 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
I tried to solve it through .env setup.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=orchid
DB_USERNAME=root
DB_PASSWORD=password
But it's not working.
After then I installed composer require doctrine/dbal package in my Laravel project but it's not working. I cannot understand how to solve it.
I try this solution. It helps me.
Log in as root to mysql
Run this sql command:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';