[英]Laravel SQLSTATE[HY000] [2002] Connection refused
so I want to deploy my existing laravel porject into my digitalocean vps I user this<\/a> tut and I upload my site successfully所以我想将我现有的 laravel 项目部署到我的 digitalocean vps 我使用
这个<\/a>tut 并成功上传了我的网站
APP_ENV=local
APP_KEY=my app key
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=my ip
DB_PORT=3306
DB_DATABASE=form
DB_USERNAME=root
DB_PASSWORD=my pass
在.env
文件中,将DB_HOST
从127.0.0.1
更改为localhost
Put string:放字符串:
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
after DB_PASSWORD=在 DB_PASSWORD= 之后
It works for MAMP.它适用于 MAMP。 Set your path to mysql.sock
将您的路径设置为 mysql.sock
There are a few possibilities why your getting this error.您收到此错误的原因有几种可能。
Check to see if this user has access to the database from the remote location.检查此用户是否可以从远程位置访问数据库。 By default the root user has access to the server locally (localhost,127.0.0.1 and ::1).
默认情况下,root 用户可以在本地访问服务器(localhost、127.0.0.1 和 ::1)。
So check to see if the user has access from either your remote ip or from anywhere.因此,请检查用户是否可以从您的远程 IP 或任何地方访问。
As you are using digitalocean I would suggest to check if they have a specific configuration to connect to mysql database.当您使用 digitalocean 时,我建议检查他们是否具有连接到 mysql 数据库的特定配置。
In your .env file, change DB_HOST from 127.0.0.1 to localhost在 .env 文件中,将 DB_HOST 从 127.0.0.1 更改为 localhost
and then进而
php artisan view:clear php工匠视图:清除
This worked for me.这对我有用。
SELinux might be the cause. SELinux 可能是原因。
Set this rule and try again:设置此规则并重试:
sudo setsebool -P httpd_can_network_connect_db=1
After long hours this worked for me:经过长时间的工作,这对我有用:
Changing the port in php My Admin previously 8889更改 php My Admin 中以前的端口为 8889
APP_NAME=laravel
APP_ENV=local
APP_KEY= YOUR KEY
APP_DEBUG=true
APP_URL=127.0.0.1
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
and then进而
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
My composer was installed globally, i run php artisan serve without starting xampp & getting this error.我的作曲家是全局安装的,我在没有启动 xampp 的情况下运行 php artisan serve 并收到此错误。 After running my xampp server, it's working fine from my side.
运行我的 xampp 服务器后,它在我这边工作正常。
In attempt to provide a solution for those of you that have not found success in any of the already mentioned answers, I will share my solution.为了为那些在任何已经提到的答案中都没有成功的人提供解决方案,我将分享我的解决方案。
Coming from Windows 10 I was of the understanding that the password for the root user was always blank thus my .env file looked as follows:从 Windows 10 开始,我了解到 root 用户的密码始终为空,因此我的 .env 文件如下所示:
DB_USERNAME=root
DB_PASSWORD=
On Mac, the password is defaulted to "root" also.在 Mac 上,密码也默认为“root”。 Changing my .env file to look as follows fixed my issue:
将我的 .env 文件更改为如下所示修复了我的问题:
DB_USERNAME=root
DB_PASSWORD=root
in your .env file在你的 .env 文件中
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=ur_db_name
DB_USERNAME=ur_db_username
DB_PASSWORD=ur_dbuser_password
Before you do changes as per instructed above,在按照上述说明进行更改之前,
command prompt
, running mysql.server
status or mysqld
status shall show the database status.command prompt
,运行mysql.server
status 或mysqld
status 将显示数据库状态。dbuser
is allow to connect from '%'
or 'localhost'
or '127.0.0.1'
.dbuser
是否允许从'%'
或'localhost'
或'127.0.0.1'
。 If not, just grant the user access from '%'
'%'
授予用户访问权限If you are using XAMPP on Mac, Just use the embedded Ip Address from your XAMPP Dashboard as DB_HOST instead of 127.0.0.1 or localhost...如果您在 Mac 上使用 XAMPP,只需使用 XAMPP 仪表板中的嵌入式 IP 地址作为 DB_HOST 而不是 127.0.0.1 或 localhost...
If It still refuses to connect deal with a user but stick on that idea.如果它仍然拒绝与用户联系,但坚持这个想法。
Thank you.谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.