我是Laravel的新手(版本5.5)。这是 config / database.php 文件:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'mfa'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'mypass'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
这是我在 routes / web.php 上的路线:
Route::get('/', function ()
{
Schema::create('books',function($newtable){
$newtable->increments('id');
$newtable->string('writer');
$newtable->string('title',500);
$newtable->text('description');
$newtable->date('published');
$newtable->integer('copies');
$newtable->timestamps();
});
return view('welcome');
});
数据库存在且名为“mfa'”,用户名为' root'。它似乎正试图以“宅基地”的形式登录。尽管它是' root'。这是一个错误代码: SQLSTATE [HY000] [1045]
答案 0 :(得分:1)
首先运行此命令以清除缓存:php artisan config:clear
.env文件:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:Pf8bqFhStKix4rtdt1FOgvPpudMqsYyw+Uv+dOvaF8w=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=mfa
DB_USERNAME=root
DB_PASSWORD=mypass
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
'mysql' => [
'driver' => 'mysql',
'port' => env('DB_PORT', '3306'),
'host' => env('DB_HOST', 'localhost'), //127.0.0.1
'database' => env('DB_DATABASE', 'mfa'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'smus82'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
注意:您需要在
.env
文件中更改后重新启动服务器。应用设置。
答案 1 :(得分:0)
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:Pf8bqFhStKix4rtdt1FOgvPpudMqsYyw+Uv+dOvaF8w=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mfa
DB_USERNAME=root
DB_PASSWORD=mypass
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=