Laradock Laravel database connection refused
Laradock Laravel database connection refused
Laradock is a PHP development environment which runs on Docker. It is a collection of images such as Nginx, Apache, MySQL, Composer, Supervisord, Redis, etc. that required for your application development. Starting with Laradock is pretty easy with the following command:
sudo docker-compose up -d nginx mysql phpmyadmin redis workspace
The above command will run all these images separated and automatically connect to your workspace environment. But in some cases connecting with the database will create the error with php artisan migrate command.
SQLSTATE[HY000] [2002] Connection refused
That is because we have the following settings in the .env file to connect with the database.
.....
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
.....
To connect your application with MySQL through Laradock, we have to set the DB_HOST=mysql instead of DB_HOST=127.0.0.1
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laraqueue
DB_USERNAME=root
DB_PASSWORD=root
But sometimes not only this works for the MySQL connection. Go to the laradock directory and find my.cnf file under the mysql directory and add the default_authentication_plugin=mysql_native_password and the file should look like the below.
[mysqld]
sql-mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
character-set-server=utf8
default_authentication_plugin=mysql_native_password
Once you added this to your file you have to rebuild the mysql image with docker-compose build mysql and again start the service. If it’s still not connecting to the Laravel, then access the mysql terminal and the following changes.
sudo docker exec -it <mysql_container_id> bash
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'default'@'%' IDENTIFIED WITH mysql_native_password BY 'secret';
Helpful Link
Related Posts:
Laradock Laravel database connection refused的更多相关文章
- “psql: could not connect to server: Connection refused” Error when connecting to remote database
问题: I am trying to connect to a postgres database installed in a remote server using the following c ...
- 【MongoDB】 Failed to connect to 127.0.0.1:27017, reason: Connection refused
由于项目需要,在一台虚拟机上安装了MongoDB,但是在启动的时候,出现如下错误: [root@localhost bin]# ./mongo MongoDB shell version v3.4.0 ...
- error: not found: value sqlContext/import sqlContext.implicits._/error: not found: value sqlContext /import sqlContext.sql/Caused by: java.net.ConnectException: Connection refused
1.今天启动启动spark的spark-shell命令的时候报下面的错误,百度了很多,也没解决问题,最后想着是不是没有启动hadoop集群的问题 ,可是之前启动spark-shell命令是不用启动ha ...
- Caused by: java.net.ConnectException: Connection refused: master/192.168.3.129:7077
1:启动Spark Shell,spark-shell是Spark自带的交互式Shell程序,方便用户进行交互式编程,用户可以在该命令行下用scala编写spark程序. 启动Spark Shell, ...
- Neo4j下执行cypher-shell时,Connection refused问题解决?
不多说,直接上干货! 问题现象 root@zhouls-/bin# ls cypher-shell neo4j neo4j-admin neo4j-import neo4j-shell tools ...
- postgres登录失败Connection refused与SSL off失败
连接失败问题 使用postgres数据库连接工具测试,遇到两次失败 第一个登录失败问题 Connection to 192.168.XX.XX:5432 refused. Check that the ...
- VNC connect:Connection refused(10061)
在Windows机器上使用VNC Viewer访问Linux服务器,有时候会遇到"connect:Connection refused(10061)"这个错误,导致这个错误出现的原 ...
- telnet报“Unable to connect to remote host:Connection refused”错误
Linux下面telnet ip 端口号 报错误"Unable to connect to remote host:Connection refused"的时候,大部分是目标机的端 ...
- ZooKeeper集群搭建中的Connection refused而导致的启动失败
1. 前言 每一次搭建集群环境都像一次战斗,作战中任何一个细节的出错都会导致严重的后果,所以搭建中所需要做的配置如系统配置.网络配置(防火墙记得关).用户权限.文件权限还有配置文件等等内容,都必须非常 ...
随机推荐
- BJFU——205基于顺序存储结构的图书信息表的排序
#include<stdio.h> #include<stdlib.h> #define MAX 1000 typedef struct{ double no; char na ...
- zabbix的离线安装方法----孙祎晨,如需转载请注明出处,谢谢配合。
------------------------zabbix的离线安装步骤--------------------------------------------------------------- ...
- 谷歌chrome浏览器提示“喔唷 崩溃啦”的解决方案
原因分析:有可能是注册列表被一些卫士类优化工具或杀毒软件优化了. 解决方案:1. 卸载谷歌浏览器. ①开始→控制面板→添加或删除程序→找到谷歌浏览器卸载(卸载时勾选删除数据) ② 进入注册列表删除谷歌 ...
- linux安装png2icon方法
此工具用于将png图片转换为ico格式的文件,一个小工具,但很实用 官网:http://www.winterdrache.de/freeware/png2ico/ 下载: wget http://ww ...
- JQuery 的优先级
1.使用最新的jQuery版本 2.用对选择器. 2.1 jquery最快的选择器是ID选择器:来源于js的getElementById()方法 注释:需要选择多个元素,必然涉及到Dom遍历和循环 ...
- VS.NET(C#)--2.8HTML服务器控件
HTML服务器控件 服务器不处理HTML控件,例如:<h1>.<a>超链接.<input>,直接送到客户端,由浏览器呈现. 把HTML控件转换成HTML服务器控件, ...
- ASP.NET Core 2.1 中的 HttpClientFactory (Part 1) HttpClientFactory介绍
原文:https://www.stevejgordon.co.uk/introduction-to-httpclientfactory-aspnetcore 发表于:2018年1月 ASP.NET ...
- C#基础加强笔记
1面向对象 类:包含字段.属性.函数.构造函数 字段:存储数据 属性:保护字段 get set 函数:描述对象的行为 构造函数:初始化对象,给对象的每个属性赋值 面向对象的好处:让程序具有扩展性 类决 ...
- Go 终端读写 && 文件读写、copy
终端读写 操作终端相关文件句柄常量 os.Stdin(standard):标准输入 os.Stdout:标准输出 os.Stderr:标准错误输出 标准输出 demo:直接输出和 判断之后输出的结果不 ...
- 目标进程已退出,但未引发 CoreCLR 启动事件
目标进程已退出,但未引发 CoreCLR 启动事件.请确保将目标进程配置为使用 .NET Core.如果目标进程未运行 .NET Core,则发生这种情况并不意外 解决:更新SDK版本