I have a problem with my Laravel application.
When I type PHP artisan migrate this shows:
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Hte inconnu. (SQL: select * from information_schema.tables where table_schema = laravel8 and table_nam e = migrations and table_type = 'BASE TABLE')
at C:\xampp\htdocs\emart\vendor\laravel\framework\src\Illuminate\Database\Connection.php:742
738▕ // If an exception occurs when attempting to run a query, we'll format the error
739▕ // message to include the bindings with SQL, which will make this exception a
740▕ // lot more helpful to the developer instead of just the database's errors.
741▕ catch (Exception $e) { ➜ 742▕ throw new QueryException(
743▕ $query, $this->prepareBindings($bindings), $e
744▕ );
745▕ }
746▕ }
1 C:\xampp\htdocs\emart\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo for mysql failed: Hte inconnu. ")
2 C:\xampp\htdocs\emart\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct()
I have already uncommented the "extension=pdo_mysql" in my php.ini and the extension_dir too
I also added the PHP to the path system But still doesn't work.
I have 2 php.ini files xampp\php\php.ini and \Program Files\php-8.1.5-Win32-vs16-x64\php.ini
Related
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
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.
I installed fresh laravel and edited .env.
Added my MAMP host:127.0.0.1, database:"abc", username:root, password:root and it then tried run command: php artisan migrate --pretend
Its gives this error:
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = abc 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|
+37 vendor frames
38 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Tried change also mamp pro port to 8889 and same issue.
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