我已经在网上找到了很好的教程,我确实做了,我已经逐步提出了建议,而且我没有将我的laravel框架与XAMPP结合起来..我不是&# 39;不知道发生了什么......我已经用.env和config / database.php写下了相同的数据配置(DB_DATABASE = styde_curso,DB_USERNAME = root和DB_PASSWORD =)。 / p>
.ENV
APP_NAME=Prueba
APP_ENV=local
APP_KEY=base64:MWU6YadaT17Ga1m3hrtOQqYq6pIwOgrNWQe+mJazyw0=
APP_DEBUG=true
APP_URL=homestead.test
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=styde_curso
DB_USERNAME=root
DB_PASSWORD=
配置/ database.php中
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'styde_curso'),
'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,
],
虽然我已申请" php artisan config:clear"我得到了相同的结果" ERROR"我已经复制了git hub注意到我的错误:
vagrant @ homestead:〜/ code / Prueba $ php artisan config:clear 配置缓存已清除! vagrant @ homestead:〜/ code / Prueba $ php 工匠移民
Illuminate \ Database \ QueryException:SQLSTATE [HY000] [1045]访问 拒绝用户&root;' @' localhost' (使用密码:否)(SQL:选择* 来自information_schema.tables,其中table_schema = styde_curso和 table_name =迁移)
在
/home/vagrant/code/Prueba/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|
异常追踪:
1 PDOException ::(" SQLSTATE [HY000] [1045]拒绝用户访问 '根' @'本地主机' (使用密码:否)") /home/vagrant/code/Prueba/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php :68
2
PDO :: __构建体(" MySQL的:主机=本地主机;端口= 3306; DBNAME = styde_curso&#34 ;, " root","",[]) /home/vagrant/code/Prueba/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php :68
我会等你的帮助或任何可以帮助我的人...... 感谢名单。
答案 0 :(得分:0)
有时,当您对.env文件进行更改而不是重新启动服务器时会出现此问题。我建议你改变主持人' => env(' DB_HOST',#39; 127.0.0.1'),到localhost,然后重启你的服务器,因为config / database也写了localhsot
答案 1 :(得分:0)
我建议将您的DB_HOST设置为127.0.0.1
DB_HOST=127.0.0.1
如果您还没有的话,我还建议为数据库root用户设置密码,这只是一个好习惯。如果选择这样做,请确保使用新密码更新.env文件。
错误告诉您登录失败:
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
错误很可能是由于凭据不正确(丢失或用户名/密码错误)导致的。或不正确的访问权限,换句话说,您的用户(在本例中为root)可能具有root@127.0.0.1的特权,但没有root @ localhost的特权。