简体   繁体   English

1 PDOException::("SQLSTATE[HY000] [2002] 无法建立连接,因为目标机器主动拒绝它

[英]1 PDOException::("SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it

Error when running :运行时出错:

php artisan migrate:reset php工匠迁移:重置

in the root of my Laravel site:在我的 Laravel 站点的根目录中:

  1   PDOException::("SQLSTATE[HY000] [2002] No connection could be made because
 the target machine actively refused it.
")
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connectors\Connector.php : 68

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=homestead", "homes
tead", "secret", [])
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connectors\Connector.php : 68

  Please use the argument -v to see more details.

When i ran the -vi got this:当我运行 -vi 时得到了这个:

  1   PDOException::("SQLSTATE[HY000] [2002] No connection could be made because
 the target machine actively refused it.
")
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connectors\Connector.php : 68

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=homestead", "homes
tead", "secret", [])
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connectors\Connector.php : 68

  3   Illuminate\Database\Connectors\Connector::createPdoConnection("mysql:host=
127.0.0.1;port=3306;dbname=homestead", "homestead", "secret", [])
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connectors\Connector.php : 44

  4   Illuminate\Database\Connectors\Connector::createConnection("mysql:host=127
.0.0.1;port=3306;dbname=homestead", [])
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connectors\MySqlConnector.php : 24

  5   Illuminate\Database\Connectors\MySqlConnector::connect()
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connectors\ConnectionFactory.php : 183

  6   Illuminate\Database\Connectors\ConnectionFactory::Illuminate\Database\Conn
ectors\{closure}()
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connection.php : 915

  7   call_user_func(Object(Closure))
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connection.php : 915

  8   Illuminate\Database\Connection::getPdo()
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connection.php : 940

  9   Illuminate\Database\Connection::getReadPdo()
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connection.php : 399

  10  Illuminate\Database\Connection::getPdoForSelect()
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connection.php : 325

  11  Illuminate\Database\Connection::Illuminate\Database\{closure}("select * fr
om information_schema.tables where table_schema = ? and table_name = ?")
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connection.php : 657

  12  Illuminate\Database\Connection::runQueryCallback("select * from informatio
n_schema.tables where table_schema = ? and table_name = ?", Object(Closure))
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connection.php : 624

  13  Illuminate\Database\Connection::run("select * from information_schema.tabl
es where table_schema = ? and table_name = ?", Object(Closure))
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Connection.php : 333

  14  Illuminate\Database\Connection::select("select * from information_schema.t
ables where table_schema = ? and table_name = ?")
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Schema\MySqlBuilder.php : 18

  15  Illuminate\Database\Schema\MySqlBuilder::hasTable("migrations")
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Migrations\DatabaseMigrationRepository.php : 169

  16  Illuminate\Database\Migrations\DatabaseMigrationRepository::repositoryExis
ts()
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Migrations\Migrator.php : 545

  17  Illuminate\Database\Migrations\Migrator::repositoryExists()
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Database\Console\Migrations\ResetCommand.php : 63

  18  Illuminate\Database\Console\Migrations\ResetCommand::handle()
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Container\BoundMethod.php : 29

  19  call_user_func_array([])
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Container\BoundMethod.php : 29

  20  Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Container\BoundMethod.php : 87

  21  Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Founda
tion\Application), Object(Closure))
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Container\BoundMethod.php : 31

  22  Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Applic
ation), [])
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Container\Container.php : 564

  23  Illuminate\Container\Container::call()
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Console\Command.php : 183

  24  Illuminate\Console\Command::execute(Object(Symfony\Component\Console\Input
\ArgvInput), Object(Illuminate\Console\OutputStyle))
      C:\Users\jarro\Documents\Sites\homestead\vendor\symfony\console\Command\Co
mmand.php : 252

  25  Symfony\Component\Console\Command\Command::run(Object(Symfony\Component\Co
nsole\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Console\Command.php : 170

  26  Illuminate\Console\Command::run(Object(Symfony\Component\Console\Input\Arg
vInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      C:\Users\jarro\Documents\Sites\homestead\vendor\symfony\console\Applicatio
n.php : 865

  27  Symfony\Component\Console\Application::doRunCommand(Object(Illuminate\Data
base\Console\Migrations\ResetCommand), Object(Symfony\Component\Console\Input\Ar
gvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      C:\Users\jarro\Documents\Sites\homestead\vendor\symfony\console\Applicatio
n.php : 241

  28  Symfony\Component\Console\Application::doRun(Object(Symfony\Component\Cons
ole\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      C:\Users\jarro\Documents\Sites\homestead\vendor\symfony\console\Applicatio
n.php : 143

  29  Symfony\Component\Console\Application::run(Object(Symfony\Component\Consol
e\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Console\Application.php : 88

  30  Illuminate\Console\Application::run(Object(Symfony\Component\Console\Input
\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      C:\Users\jarro\Documents\Sites\homestead\vendor\laravel\framework\src\Illu
minate\Foundation\Console\Kernel.php : 121

  31  Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Cons
ole\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      C:\Users\jarro\Documents\Sites\homestead\artisan : 37

I think i know what is going on.我想我知道发生了什么。 I have had to change my database connection to 192.168.10.10 in PHPStorm to connect to MySQL because the MySQL is on the homestead VM (virtual machine) and i cant connect to it locally because technically its on a "Different Machine".我不得不在 PHPStorm 中将我的数据库连接更改为 192.168.10.10 以连接到 MySQL,因为 MySQL 在 homestead VM(虚拟机)上,我无法在本地连接到它,因为技术上它在“不同的机器”上。 So then i went looking for where to change database info.然后我去寻找在哪里更改数据库信息。 My queries work as of now.我的查询现在有效。 So i don't know why this is having issues.所以我不知道为什么这有问题。 I found the /config/database.php and changed every username, password, db name, host to the correct things :我找到了 /config/database.php 并将每个用户名、密码、数据库名称、主机更改为正确的内容:

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', '192.168.10.10'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'homestead'),
    'username' => env('DB_USERNAME', 'homestead'),
    'password' => env('DB_PASSWORD', 'secret'),
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'strict' => true,
    'engine' => null,
],

'pgsql' => [
    'driver' => 'pgsql',
    'host' => env('DB_HOST', '192.168.10.10'),
    'port' => env('DB_PORT', '5432'),
    'database' => env('DB_DATABASE', 'homestead'),
    'username' => env('DB_USERNAME', 'homestead'),
    'password' => env('DB_PASSWORD', 'secret'),
    'charset' => 'utf8',
    'prefix' => '',
    'schema' => 'public',
    'sslmode' => 'prefer',
],

'sqlsrv' => [
    'driver' => 'sqlsrv',
    'host' => env('DB_HOST', '192.168.10.10'),
    'port' => env('DB_PORT', '1433'),
    'database' => env('DB_DATABASE', 'homestead'),
    'username' => env('DB_USERNAME', 'homestead'),
    'password' => env('DB_PASSWORD', 'secret'),
    'charset' => 'utf8',
    'prefix' => '',
],

But this, didn't really help.但这,并没有真正的帮助。 I did the command我做了命令

vagrant reload --provision流浪者重新加载 --provision

to make sure that wasn't an issue.以确保这不是问题。 It is saying in the error message in the terminal它在终端的错误消息中说

2 2
PDO::__construct("mysql:host= 127.0.0.1 ;port=3306;dbname=homestead", "homes tead", "secret", []) PDO::__construct("mysql:host= 127.0.0.1 ;port=3306;dbname=homestead", "homestead", "secret", [])


127.0.0.1 127.0.0.1


When i clearly changed the host in the database.php file in the /config to 192.168.10.10, which works when trying to connect with phpstorm.当我清楚地将 /config 中 database.php 文件中的主机更改为 192.168.10.10 时,这在尝试与 phpstorm 连接时有效。

I am having a hard time learning laravel and i am confused on how to get this changed to 192.168.10.10.我在学习 Laravel 时遇到了困难,我对如何将其更改为 192.168.10.10 感到困惑。 Can an experienced person or at least anyone try to tell me the right direction to help me find the variable $dsn to change the host being passed in it?有经验的人或至少任何人都可以尝试告诉我正确的方向来帮助我找到变量 $dsn 来更改传入的主机吗?

Any help is appreciated!任何帮助表示赞赏!

Try running php artisan cache:clear or php artisan config:clear 尝试运行php artisan cache:clearphp artisan config:clear

You might also have a .env file overriding it possibly. 您可能还会有一个.env文件,可能会覆盖它。

尝试编辑根文件夹中的 .env 文件或根文件夹中的 .env.example 文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP Laravel Doctrine \\ DBAL \\ PDOException SQLSTATE [HY000] [2002]无法建立连接,因为目标计算机主动拒绝了它 - PHP Laravel Doctrine\DBAL\PDOException SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it SQLSTATE[HY000] [2002] 无法建立连接,因为目标机器主动拒绝它 - SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it LARAVEL SQLSTATE [HY000] [2002]无法建立连接,因为目标计算机主动拒绝了它 - LARAVEL SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it php:SQLSTATE [HY000] [2002]无法建立连接,因为目标计算机主动拒绝它 - php: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it 错误:SQLSTATE[HY000] [2002] 无法建立连接,因为目标机器主动拒绝它 - ERROR: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it Laravel: SQLSTATE HY000 2002 无法建立连接,因为目标机器主动拒绝它 - Laravel: SQLSTATE HY000 2002 No connection could be made because the target machine actively refused it 驱动程序发生异常:SQLSTATE[HY000] [2002] 由于目标机器主动拒绝,无法建立连接。 - Symfony 中的错误 - An exception occurred in driver: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. - error in Symfony mysqli_connect(): (HY000/2002): 由于目标机器主动拒绝,无法建立连接 - mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it mysqli::real_connect(): (HY000/2002): 由于目标机器主动拒绝,无法建立连接 - mysqli::real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it 无法连接到数据库,并显示错误消息(HY000 / 2002):无法建立连接,因为目标计算机主动拒绝了它 - Can't connect to database with error (HY000/2002): No connection could be made because the target machine actively refused it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM