我在创建数据库表时遇到了问题。
首先我创建模型:
php artisan make:model Company -m
其次,我更新了迁移公司文件,添加了我需要的列
第三,我要去phpMyAdmin
并创建一个名为test
第四,我运行命令php artisan migrate
或php artisan migrate:install
,我有下一个错误:
[Illuminate\Database\QueryException]SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = test and table_name = migrations)
[PDOException]SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
在database/config.php
我编辑mysql驱动程序:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'test'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'pass'),
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
.env file
:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=pass
我还尝试使用php artisan config:clear
清除缓存。
任何人都可以帮助我吗?我不明白这是什么问题。
谢谢
答案 0 :(得分:0)
您的“root”密码不正确,或者可能没有所需的权限。
[PDOException]SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
重置“root”密码:
https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords
授予“root”用户权限:
Ubuntu:https://www.liquidweb.com/kb/how-to-add-a-user-and-grant-root-privileges-on-ubuntu-14-04/
Centos:https://www.liquidweb.com/kb/how-to-add-a-user-and-grant-root-privileges-on-centos-7/
然后再试一次:))
OP(OSX)的更新:
答案 1 :(得分:0)
将密码字段编辑为"密码' => env(' DB_PASSWORD','')和.env文件DB_PASSWORD =将字段保持为空,如此处所示