-1

Quando tento rodar o comando no workspace do laradock php artisan migrate ocorre o seguinte erro:

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations)

  at /var/www/blog_teste/blog/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 

  Exception trace:

  1   PDOException::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]")
      /var/www/blog_teste/blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

  2   PDO::__construct("mysql:host=mysql;port=3306;dbname=blog", "root", "root", [])
      /var/www/blog_teste/blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

  Please use the argument -v to see more details.

Essa é a configuração do arquivo .env do laradock

### MYSQL #################################################

MYSQL_VERSION=latest
MYSQL_DATABASE=default
MYSQL_USER=default
MYSQL_PASSWORD=secret
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d

Essa é a o .env do laravel

APP_NAME=Laravel

APP_ENV=local
APP_KEY=base64:Mxx0n7ac05Sz1lPasIe2TJZLqPke11oFLj5udxKKpP4=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=root

Quando tento conectar no phpMyadmin ele entra normal:

url: http://localhost:8080 
servidor: mysql
usuario: root
senha:root

PS: Quando estou fora do worskpace do laradock e altero o .env do projeto para DB_HOST=127.0.0.1 e rodo o comando php artisan migrate ele funciona.

1 Resposta 1

0

Problema resolvido Ao utilizar no .env do laradock MYSQL_VERSION=lasted ele utilizou o mysql 8.0 e houve problema. Por isso alterei para o 5.7 da seguinte forma:

docker-compose down

Alterar o .env do laradock

...
MYSQL_VERSION=5.7
...

Apagar os bancos de dados: remove todas as tabelas do banco!!

rm -rf ~/.laradock/data/mysql

Fazer o build

docker-compose build mysql

Subir novamente

docker-compose up -d apache2 mysql phpmyadmin

Solução encontrada aqui

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .