使用Mac OS X,MAMP 5.5和Laravel 5.8.35
当我使用“ php artisan migration”时,出现以下错误消息:
Illuminate \ Database \ QueryException:SQLSTATE [HY000] [2002]连接被拒绝(SQL:从information_schema.tables中选择*,其中table_schema = auth,table_name =迁移,并且table_type ='BASE TABLE')
在/Applications/MAMP/htdocs/auth/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
文件.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=auth
DB_USERNAME=etn
DB_PASSWORD=pass
与
相同DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=auth
DB_USERNAME=etn
DB_PASSWORD=pass
迁移文件
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
第二个迁移文件:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('password_resets');
}
}
答案 0 :(得分:0)
尝试此更改
DB_PORT=33060
或
DB_PORT=8889
更改后停止并重新启动服务器。
答案 1 :(得分:0)
原因之一是服务器XAMPP尚未启动,请尝试检查服务器是否已正确启动或在本地主机上没有启动。