Solvedlaradock SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

Info:

  • Docker version ($ docker --version): Docker version 17.12.0-ce, build c97c6d6
  • Laradock commit ($ git rev-parse HEAD): 8323c659ed588ad2d2b02a13dfab651c051302e8
  • System info (Mac, PC, Linux): MacOS Sierra 10.12.6
  • System info disto/version:

Issue:

Using the mysql and nginx containers, running a migration yields the following error: The server requested authentication method unknown to the client [caching_sha2_password].

This seems to be due to mysql 8.x forcing a new password format. Attempting to force old_passwords=1 from inside the mysql container yields ERROR 1231 (42000): Variable 'old_passwords' can't be set to the value of '1'.

This does occur when trying to run a migration from inside the workspace - where both the version of php and mysql should be controlled by Laradock.


Expected behavior:

Laravel should be able to login to the database and do its thing.


Reproduce:

Pull clean copy of Laradock, set DB_HOST=127.0.0.1 in .env (for reasons unknown to me, DB_HOST=mysql yields SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known), start the mysql and nginx containers, enter the workspace container and run php artisan migrate.


45 Answers

✔️Accepted Answer

+1, I'm having the same problem here.

Other Answers:

Me too, same problem .

i did resolved the problem following:

  1. add default authentication plugin to laradock/mysql/my.cnf
[mysqld]
default_authentication_plugin= mysql_native_password
  1. update content file mysql/docker-entrypoint-initdb.d/createdb.sql like:
CREATE USER 'admin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpass';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
CREATE USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY 'yourpass';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;
#
CREATE DATABASE IF NOT EXISTS `yourdb` COLLATE 'utf8_general_ci' ;
GRANT ALL ON `yourdb`.* TO 'admin'@'%' ;
FLUSH PRIVILEGES ;

important note: remove old user, database and recreate again by above script.
3. Remove mysql container and re-run it.
4. php artisan migrate is done :)

Reason bug:
Default authenticate of MySQL 8.0.4 changed.
Refer to detail information: https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-4.html
at Security Notes

hope it help you.
Thanks

Thanks @rockerbom for the thorough response. I didn't try your steps, but ended up with a different solution (for anyone that doesn't necessarily need MySQL 8.x):

  1. Changed MYSQL_VERSION to 5.7 in laradock/.env
  2. docker-compose build --no-cache mysql

@robindijkhof Use this to solve problem :
#1407

**stop all service docker-compose down
Edit .env file set MYSQL_VERSION=5.7 or MYSQL_VERSION=latest

Delete mysql database

$ rm -rf ~/.laradock/data/mysql

rebuild mysql image

$ docker-compose build mysql

retry

$ docker-compose up -d nginx mysql phpmyadmin
It's working for me.**

Have a stable solution after a few days banging thy head. MySQL 8.0 is not stable at all for me. I am surprised it is a part of Laradock. Does anyone know why a dev version is included VS a production version? Once I downgraded to 5.7 all errors above are gone and my head is healing. Like to suggest to the developers of Laradock to please use a stable version of MySQL so others may not need to travel the road of misery.

Related Issues:

684
laradock Mysql. The server requested authentication method unknown to the client [caching_sha2_password]
alter user 'username'@'localhost' identified with mysql_native_password by 'password'; would fix it....
292
laradock SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
+1 I'm having the same problem here. Info: Docker version ($ docker --version): Docker version 17.12...
178
laradock MySQL Container fails to start
I had the same issue last night I think it's the mysql version problem What I did was edited laradoc...
102
laradock ERROR: 404 page not found
I had this problem because the root path in docker-compose.yml differs from the one in nginx default...
99
laradock When Using docker-compose up mysql MySQL Doesn't Start
I solved this problem This is because of data folder I was running it using mysql 5.7 then abort it ...
94
laradock Guzzle/Curl connections between multiple projects
That's literary the only change you need to do not going to post the whole of docker-compose file in...
45
laradock Fails to initialize MySQL database
edit .env DATA_SAVE_PATH=~/.laradock/data to DATA_SAVE_PATH=./data Absolute directory d:\docker_www\...
45
laradock Laradock mysql exited with code 2
'/tmp' dir not exists on windows please help ...
38
laradock Unable to start up MySQL container
Do you have any important databases in your machine? If you have no dbs there I think you should rem...
38
laradock SQLSTATE[HY000] [2002] Connection refused
@asolopovas change your db host to mysql DB_CONNECTION=mysql DB_HOST=mysql Hi I am running laradock ...
33
laradock How to add SSL to NGINX in laradock.
Within your site config file you will want something similar to the below You will then want to add ...
24
laradock Routing issue with Laravel and Guzzle
could you try changing 127.0.0.1 to your web server container name whether it's nginx or apache2 lik...
22
laradock No way to authorize private channels in laravel-echo-server
I solve this problem by adding an alias to nginx service in docker-compose.yml reference: aliases in...
22
laradock Laradock with both php 5.6 and 7.0
I needed php-fpm 7.0 and 5.6 Hello ...
21
laradock How can I connect to mysql from outside? Like Workbrench
@pablorsk You can forward the MySQL port to your host by adding the lines To the mysql section of th...
19
laradock Mariadb plugin 'InnoDB' init function returned error.
The only way I found round this was to backup my /var/lib/mysql and /var/lib/mariadb directories by ...
16
laradock Too many errors
@lisabonde Please copy the env-example file to .env Within the .env file you can then set your prefe...
15
laradock Can't install Node & npm
The .env file also has a WORKSPACE_INSTALL_PYTHON which is set to false by default If you set it to ...
15
laradock How to connect database with my own project with laradock?
@at-tienpham check all container state is up try login PHPMyAdmin: Open Browser http://localhost:88 ...
14
laradock Multiple sites (Run many laravel projects)
I forked this for work and have an implementation of this working What I did is merge application an...
13
laradock Docker on Mac is slow
Found the solution: IFSight/d4m-nfs#5 In order to be able to use d4m-nfs you just need to perform th...
12
laradock xDebug PhpStorm Working Via CLI - Not Working Via Web Page/Apache
@fideloper all you need is xdebug.remote_connect_back = Off Here is a quote from xdebug documentatio...
11
laradock No releases available for package "pecl.php.net/xdebug"
Doing pecl channel-update pecl.php.net as suggested by @ivanferrer solved the problem for me ...
11
laradock Secure Nginx with Let's Encrypt Guide
Just yesterday i solved this problem for me with nginx Problem Definition There doesn't seem to be a...
11
laradock Two databases in one MySQL container
If you are struggling with having a non-root user for all databases on container init integrating wh...
6
laradock Docker-sync integration does not work this way - it has no effect right now
@godbout I was able to get it working on Windows Due to https://github.com/laradock/laradock/blob/ma...
5
laradock Cannot build php-fpm
Ok I've just got it working although I'm still not sure on the exact cause When try run docker-compo...
4
laradock Add Crontab and Supervisor
For the queue part I've simply added a service to the stack: add crontab and supervisor support if w...
3
laradock Elixir/Mix with Browsersync
@cjmaxik Great! Try using the hostnames nginx and caddy. So I finally managed to have Browsersync wo...
3
laradock MSSQL Initialise Problem
Hi @Nelsoft-EphraimLambarte it happened a couple of months ago not sure if it´s fixed now but I'm no...
654
nvidia docker OpenCV Docker error "ImportError: libSM.so.6: cannot open shared object file: No such file or directory"
I fixed this problem on nvcr.io/nvidia/tensorflow:18.12-py3 with (using solution above): ...
457
compose Docker-compose up failing because "port is already allocated"
I ran into the same issue today (with a postgres container) and despite having tried docker-compose ...
447
moby The name "/data-container-name" is already used by container <hash>. You have to remove (or rename) that container to be able to reuse that name.
I have a helper function to nuke everything so that our Continuous blah cycle can be tested erm.. co...
371
compose Compose error "HTTP request took too long to complete"
By simply restarting the docker service via sudo service docker restart I was able to get the aforem...
369
compose error on launching docker-compose by piping to sh ( echo 'docker-compose ... ' | sh )
I could get it to work by adding the -T parameter to not create a Pseudo-TTY docker-compose exec -T ...
337
compose docker-compose up fails if network attached to container is removed
Thanks for the report! I think there are several things to note here: First and foremost ...
316
nvidia docker docker: Error response from daemon: Unknown runtime specified nvidia.
I've also installed correctly but forgot to restart daemon in ubuntu it may resolve your error. ...
297
compose Error when trying to run docker-compose up. "oci runtime error: container_linux.go:247..."
you gotta make the docker-entrypoint.sh an executable before building the image: otherwise it cant b...
257
compose docker-compose up doesn't pull down latest image if the image exists locally
Imagine that git didn't have pull because git fetch && git merge origin/master is functionally ident...
236
nvidia docker could not select device driver "" with capabilities: [[gpu]].
Hello! If you didn't already make sure you've installed the nvidia-container-toolkit If this doesn't...
205
moby docker-engine 1.10.2-0~trusty can't install on clean Ubuntu 64-bit 14.04.3
I seem to have resolved this by putting deb http://cz.archive.ubuntu.com/ubuntu trusty main in /etc/...
183
moby Docker service update --image "could not accessed on a registry to record its digest"
When updating services that need credentials to pull the image you need to pass --with-registry-auth...
169
compose Docker Compose mounts named volumes as 'root' exclusively
Actually I come here with news it seems what I am trying to achieve is doable but I don't know if th...
149
compose INTERNAL ERROR: cannot create temporary directory!
Confirming this happened to me Today Was running low on space: After removing a container.. it works...
147
cookiecutter django No support for python3? I am getting: invalid syntax: raise ValueError, "No frame marked with %s." % fname
For me the issue was that I installed the environ package instead of the django-environ package. ...
147
compose docker-compose up -d doesn't expose ports when defined with build directive
oh you didn't specify but I'm assuming you're using run instead of up? If so you need --service-port...
142
compose How does compose chooses subnet for default network?
I'm also running into this issue Another way around this is to set the default-address-pools in your...
139
ddev In WSL2 ddev start fails at docker-credential-desktop.exe, "error listing credentials"
I had to set credsStore: in my ~/.docker/config.json .. it was previously set to credentials.exe ...