har*_*hit 9 php mysql laravel laravel-5
我试着跑: php artisan migrate
还可以在 Windows 上使用 Xampp 连接到 MySQL。
我收到这个错误:
Illuminate\Database\QueryException : SQLSTATE[HY000] [1044] Access
denied for user ''@'localhost' to database 'homestead' (SQL: select *
from information_schema.tables where table_schema = homestead and
table_name = migrations)
at
C:\Users\harsh\Laravel1\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668| Exception trace:
1 PDOException::("SQLSTATE[HY000] [1044] Access denied for user
''@'localhost' to database 'homestead'")
C:\Users\harsh\Laravel1\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
2
PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=homestead",
"homestead", "", [])
C:\Users\harsh\Laravel1\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
Please use the argument -v to see more details.
Run Code Online (Sandbox Code Playgroud)
.env 文件:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=
Run Code Online (Sandbox Code Playgroud)
打开.env文件并进行编辑。只需设置正确的数据库凭据:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Yout Database Username
DB_PASSWORD= // Your Database Password
Run Code Online (Sandbox Code Playgroud)
该DB_USERNAME应设置为root,如果你没有一个默认的用户名在MySQL安装的XAMPP。
如果数据库没有设置密码,清除它DB_PASSWORD,空格也必须删除(以前我也遇到过这个问题,window把空格当作密码)
.env编辑完成后,请在终端中输入此命令以清除缓存:
php artisan config:cache
Run Code Online (Sandbox Code Playgroud)