Laradock Laravel database connection refused

SHARE 

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

 

Laradock Laravel database connection refused的更多相关文章

  1. “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 ...

  2. 【MongoDB】 Failed to connect to 127.0.0.1:27017, reason: Connection refused

    由于项目需要,在一台虚拟机上安装了MongoDB,但是在启动的时候,出现如下错误: [root@localhost bin]# ./mongo MongoDB shell version v3.4.0 ...

  3. 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 ...

  4. Caused by: java.net.ConnectException: Connection refused: master/192.168.3.129:7077

    1:启动Spark Shell,spark-shell是Spark自带的交互式Shell程序,方便用户进行交互式编程,用户可以在该命令行下用scala编写spark程序. 启动Spark Shell, ...

  5. Neo4j下执行cypher-shell时,Connection refused问题解决?

    不多说,直接上干货!  问题现象 root@zhouls-/bin# ls cypher-shell neo4j neo4j-admin neo4j-import neo4j-shell tools ...

  6. postgres登录失败Connection refused与SSL off失败

    连接失败问题 使用postgres数据库连接工具测试,遇到两次失败 第一个登录失败问题 Connection to 192.168.XX.XX:5432 refused. Check that the ...

  7. VNC connect:Connection refused(10061)

    在Windows机器上使用VNC Viewer访问Linux服务器,有时候会遇到"connect:Connection refused(10061)"这个错误,导致这个错误出现的原 ...

  8. telnet报“Unable to connect to remote host:Connection refused”错误

    Linux下面telnet ip 端口号 报错误"Unable to connect to remote host:Connection refused"的时候,大部分是目标机的端 ...

  9. ZooKeeper集群搭建中的Connection refused而导致的启动失败

    1. 前言 每一次搭建集群环境都像一次战斗,作战中任何一个细节的出错都会导致严重的后果,所以搭建中所需要做的配置如系统配置.网络配置(防火墙记得关).用户权限.文件权限还有配置文件等等内容,都必须非常 ...

随机推荐

  1. ~jmeter解决csrftoken登录问题

    一.登录接口 url:http://192.168.163.128:/user/login/ 请求方法:post 请求参数: account:用户名 password:登录密码 remember:是否 ...

  2. SPA项目首页导航+左侧菜单

    Mock.js是个啥 前后端分离之后,前端迫切需要一种机制,不再需要依赖后端接口开发,而今天的主角mockjs就可以做到这一点 Mock.js是一个模拟数据的生成器,用来帮助前端调试开发.进行前后端的 ...

  3. mouseenter 与 mouseover 区别于选择

    mouseover事件, 箭头在子元素移动会触发冒泡事件,  子元素的鼠标箭头可触父元素方法, 相反,mouseenter事件功能与mouseover类似, 但鼠标进入某个元素不会冒泡触发父元素方法. ...

  4. Spring Cloud Alibaba学习笔记(7) - Sentinel规则持久化及生产环境使用

    Sentinel 控制台 需要具备下面几个特性: 规则管理及推送,集中管理和推送规则.sentinel-core 提供 API 和扩展接口来接收信息.开发者需要根据自己的环境,选取一个可靠的推送规则方 ...

  5. poj 3252 数位dp

    题意:一个二进制的数,如果0的个数大于1的个数,那么我们称这个数为Round Numbers,求给定区间(十进制表示)中Round Numbers的个数 题解:数位dp,不过这里枚举的时候lead标记 ...

  6. python之统计字符串中字母出现次数

    dic=dict() d={} s=set() s='helloworld' (1)d=dict() for x in s: if x not in d.keys(): d[x]=1 else: d[ ...

  7. iOS - Scenekit3D引擎初探之 - 导出DAE文件(3Dmax为例)

    DAE文件格式是3D交互文件格式,一般用于多个图形程序之间交换数字数据,Autodesk专有并在COLLADA(COLLAborative Design Activity)基础上改进创建的XML框架的 ...

  8. 如何设置MySql Server远程访问(Debian Linux)

    1. 登录Mysql Server: $mysql -u root -p 2. 检查网络,Server是否允许远程连接: mysql> show variables like '%skip_ne ...

  9. S5PV210 PWM

    定时器PWM输出 原理图 GPD0CON, R/W, Address = 0xE020_00A0 CON, R/W, Address = 0xE250_0008 相关文章:http://blog.cs ...

  10. Vue路由规则中定义参数

    Vue使用routerLinke定义参数的时候  路由规则中不需要更改任何属性. 路由其实就是我们在html中定义的锚点,点击这个连接跳转一个锚点.vue中的路由也是这个原理, 前提是路由必须创建在实 ...