我今天刚刚开始下载laravel 5。我在桌面上安装laravel的地方。当我尝试使用laravel comman创建一个数据库php artisan migrate:install并且它给了我一个错误SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge'
我在谷歌上尝试了很多例子但是对我没用。
我按照互联网上的步骤配置我的.env
文件,其中数组包含database.php
数据库中的'forge'
,用户名为'forge'
,密码为''
database.php中
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
],
.ENV
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:oqZ6S+IZANLCbszbhef9VSPqd/4rw22oT0mixzsflZo=
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=forge
DB_USERNAME=forge
DB_PASSWORD=''
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=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
如何创建数据库只需键入php artisan migrate:install
并在我的localhost中自动创建laravel_migration
数据库?刚看到这个在互联网上。但是当我这样做时,它并没有为我创造。
答案 0 :(得分:0)
正如评论中所提到的,本教程假设您正在使用他们的开发虚拟机。既然你没有,你需要启动MySQL并执行以下操作:
CREATE DATABASE IF NOT EXISTS forge;
CREATE USER forge@localhost IDENTIFIED BY '';
GRANT ALL PRIVILEGES ON forge.* TO forge@localhost;
创建数据库和用户后,您应该很高兴。这应该是他们文件的一部分......