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. 前言 每一次搭建集群环境都像一次战斗,作战中任何一个细节的出错都会导致严重的后果,所以搭建中所需要做的配置如系统配置.网络配置(防火墙记得关).用户权限.文件权限还有配置文件等等内容,都必须非常 ...
随机推荐
- Python06之分支和循环1(三目运算符)
Python 为了使得程序更加简洁而新引入过来的一个三目操作符,顾名思义就是有三个参数. 格式: x if 条件表达式 else y 先判断条件表达式真假,真则取 x 的值,否则取 y 的值. 例如: ...
- WUSTOJ 1336: Lucky Boy(Java)博弈
题目链接:1336: Lucky Boy 参考博客:LUCKY BOY 博弈--HandsomeHow Description Recently, Lur have a good luck. He i ...
- NodeJS的环境搭建+传统ELmentui+vue开发
ElementUI简介 我们学习VUE,知道它的核心思想式组件和数据驱动,但是每一个组件都需要自己编写模板,样式,添加事件,数据等是非常麻烦的, 所以饿了吗推出了基于VUE2.0的组件库,它的名称叫做 ...
- Vue使用指南(三)
组件 '''1.根组件:new Vue()创建的组件,一般不明确自身的模板,模板就采用挂载点2.局部组件: local_component = {}2.全局组件: Vue.component({})' ...
- MAMP PRO 在osx 10.10 错误处理
新更新的osx10.10之后,启动MAMP会发现Apache无法启动, 处理如下: 1.cd /Applications/MAMP/Library/bin 2.mv envvars _envvars ...
- Bipartite Checking CodeForces - 813F (线段树按时间分治)
大意: 动态添边, 询问是否是二分图. 算是个线段树按时间分治入门题, 并查集维护每个点到根的奇偶性即可. #include <iostream> #include <sstream ...
- 集合并卷积的三种求法(分治乘法,快速莫比乌斯变换(FMT),快速沃尔什变换(FWT))
也许更好的阅读体验 本文主要内容是对武汉市第二中学吕凯风同学的论文<集合幂级数的性质与应用及其快速算法>的理解 定义 集合幂级数 为了更方便的研究集合的卷积,引入集合幂级数的概念 集合幂级 ...
- go的安装及环境变量设置
1,go安装 https://studygolang.com/dl 官网下载,找自己需要的版本,傻瓜式安装 2.go的环境变量设置 windows下面要设置root和path root代表go安装路径 ...
- 数据结构与算法(周测3-Huffman树)
判断题 1.Given a Huffman tree for N (≥2) characters, all with different weights. The weight of any non- ...
- C++——virtual function
无论是pure virtual还是impure virtual,都允许子类override他.但是真两种方式还是有一点差别,如果是pure virtual,那么父类是十分强烈希望子类override他 ...