gpt4 book ai didi

php - 我是 laravel 的初学者。我在 laravel 版本 5.4.16 上遇到了与 mysql 的连接错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:38:24 25 4
gpt4 key购买 nike

这是我将表添加到 firstapp db 的路由代码

Route::get('/', function () 
{
Schema::create('users', function($table)
{
$table->increments('id');
});
return view('welcome');
});

这是 config\database.php 文件的代码

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

但是有两个错误。请给我解决方案。

QueryException in Connection.php line 647: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. (SQL: create table users (id int unsigned not null auto_increment primary key) default character set utf8mb4 collate utf8mb4_unicode_ci)

PDOException in Connector.php line 68: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

最佳答案

你必须修改环境文件。有一些数据库配置必须首先修改,而不是像修改 database.php 文件一样

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=Your Db Name
DB_USERNAME=Your Db username
DB_PASSWORD=Your Db Password

关于php - 我是 laravel 的初学者。我在 laravel 版本 5.4.16 上遇到了与 mysql 的连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43229183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com