I am a newbie to both PHP and Laravel. Now I wish to connect my Laravel project to Mysql. But when I add the auth
and try to register as an user, an error of Access denied for user 'yobichi'@'localhost' (using password: NO)
occured. Here are the content of my .env
file:
我是PHP和Laravel的新手。现在我希望将我的Laravel项目连接到Mysql。但是当我添加auth并尝试注册为用户时,用户'yobichi'@'localhost'(使用密码:NO)的访问被拒绝错误。以下是我的.env文件的内容:
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:B21yfOUcsb5zmtlga5lori7olUMIGjeWhU2IrQ4grSc=
APP_URL=http://laravel.app
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravelDB
DB_USERNAME=yobichi
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
I wonder whether I have any setting wrong in the .env
file? Why can't I access the db properly? Thank you in advance!!!
我想知道.env文件中是否有任何设置错误?为什么我不能正确访问数据库?先谢谢你!!!
3 个解决方案
#1
0
You need to check if user yobichi exists an has permission to read/write in laravelDB and also have to setup a password for your database user.
您需要检查用户yobichi是否存在laravelDB中的读/写权限,还必须为数据库用户设置密码。
#2
0
If I remember correctly, Laravel requires you to have a password on your DB account.
如果我没记错的话,Laravel要求您在数据库帐户上设置密码。
Also, have you actually created the user on your database?
另外,您是否真的在数据库中创建了用户?
#3
0
If you're using Homestead, you should use these settings:
如果您使用的是Homestead,则应使用以下设置:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=homestead
DB_PASSWORD=secret
Also, you should connect to MySQL and create db_name
database to use it.
此外,您应该连接到MySQL并创建db_name数据库以使用它。
#1
0
You need to check if user yobichi exists an has permission to read/write in laravelDB and also have to setup a password for your database user.
您需要检查用户yobichi是否存在laravelDB中的读/写权限,还必须为数据库用户设置密码。
#2
0
If I remember correctly, Laravel requires you to have a password on your DB account.
如果我没记错的话,Laravel要求您在数据库帐户上设置密码。
Also, have you actually created the user on your database?
另外,您是否真的在数据库中创建了用户?
#3
0
If you're using Homestead, you should use these settings:
如果您使用的是Homestead,则应使用以下设置:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=homestead
DB_PASSWORD=secret
Also, you should connect to MySQL and create db_name
database to use it.
此外,您应该连接到MySQL并创建db_name数据库以使用它。