Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

Unable to connect to local MySQL DB using Laravel

I have a local database that I can connect to no problem using straight php

Working Example

However, when I use the same settings in Laravel, I get an access denied error message

enter image description here

I checked stackoverflow for this type of error and most cases is solved by using 127.0.0.1. I made sure to try both 127.0.0.1 and localhost whenever asked for host/server.

Also, I made sure root had sufficient privileges

mysql User Root Privileges

Here are my configuration settings, I tried to use different accounts, other than root, and also changing 127.0.0.1 to localhost (and the opposite)

database.php file

enter image description here

.env file

enter image description here

Hoping to learn this framework, I've heard great things. Appreciate any help

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Sounds like you are trying the connection both with the script and laravel from a different Server like homestead.

Normally there are restrictions that you can't connect from remote (i.e. from a VM like homestead) to a certain server (i.e. localhost) with the root user.

Possible Solutions: 1. Create another user with the relevant permissions on mysql and connect with that one. 2. Look in the web for how to allow remote connections 3. Go the laravel way and use the homestead DB inside of the VM


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...