无法使用Laravel连接到本地MySQL DB [英] Unable to connect to local MySQL DB using Laravel

查看:114
本文介绍了无法使用Laravel连接到本地MySQL DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地数据库,可以使用直接php毫无问题地连接到

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

但是,当我在Laravel中使用相同的设置时,会收到拒绝访问错误消息

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

我检查了stackoverflow中是否存在这种类型的错误,大多数情况下可以通过使用127.0.0.1解决.每次询问主机/服务器时,我都确保同时尝试127.0.0.1localhost.

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.

此外,我确保root拥有足够的特权

Also, I made sure root had sufficient privileges

这是我的配置设置,我尝试使用除root以外的其他帐户,并将127.0.0.1更改为localhost(相反)

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文件

database.php file

.env文件

希望学习此框架,我听说过很多很棒的事情.感谢任何帮助

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

推荐答案

听起来像您正在尝试从其他服务器(例如宅基地)与脚本和laravel进行连接.

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

通常,存在一些限制,您无法使用root用户从远程(即从类似Homestead的VM)连接到特定服务器(即localhost).

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.

可能的解决方案: 1.在mysql上创建具有相关权限的另一个用户,然后与该用户连接. 2.在网络上查找如何允许远程连接 3.采取laravel的方法,并在VM内使用homestead数据库

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

这篇关于无法使用Laravel连接到本地MySQL DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆