1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Docker環境のLaravelでSchema dumpする

Last updated at Posted at 2023-09-26

やりたいこと

Docker環境のLaravel8以上でphp artisan schema:dumpのmigrationをsqlファイルに圧縮してくれるコマンドを実行したかった(当環境はLaravel 10)

ベースイメージはphp:8.1-fpm-buster

発生したエラー

1. そもそもmysqldumpがないエラー


php artisan schema:dump
sh: 1: mysqldump: not found
sh: 1: mysqldump: not found
sh: 1: mysqldump: not found

   Symfony\Component\Process\Exception\ProcessFailedException 

  The command "mysqldump  --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --no-tablespaces --skip-add-locks --skip-comments --skip-set-charset --tz-utc "${:LARAVEL_LOAD_DATABASE}" --routines --result-file="${:LARAVEL_LOAD_PATH}" --no-data" failed.

Exit Code: 127(Command not found)

Working directory: /var/www/html

Output:
================


Error Output:
================
sh: 1: mysqldump: not found

  at vendor/symfony/process/Process.php:267
    263▕      */
    264▕     public function mustRun(callable $callback = null, array $env = []): static
    265▕     {
    266▕         if (0 !== $this->run($callback, $env)) {
  ➜ 267▕             throw new ProcessFailedException($this);
    268▕         }
    269▕ 
    270▕         return $this;
    271▕     }

      +17 vendor frames 

  18  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

2. Plugin caching_sha2_password could not be loadedエラー

mysqldumpを使えるようになった後に起こる


php artisan schema:dump
mysqldump: unknown variable 'column-statistics=0'
mysqldump: unknown variable 'set-gtid-purged=OFF'
mysqldump: Got error: 1045: "Plugin caching_sha2_password could not be loaded: /usr/lib/aarch64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory" when trying to connect

   Symfony\Component\Process\Exception\ProcessFailedException 

  The command "mysqldump  --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --no-tablespaces --skip-add-locks --skip-comments --skip-set-charset --tz-utc "${:LARAVEL_LOAD_DATABASE}" --routines --result-file="${:LARAVEL_LOAD_PATH}" --no-data" failed.

Exit Code: 2(Misuse of shell builtins)

Working directory: /var/www/html

Output:
================


Error Output:
================
mysqldump: Got error: 1045: "Plugin caching_sha2_password could not be loaded: /usr/lib/aarch64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory" when trying to connect

  at vendor/symfony/process/Process.php:267
    263▕      */
    264▕     public function mustRun(callable $callback = null, array $env = []): static
    265▕     {
    266▕         if (0 !== $this->run($callback, $env)) {
  ➜ 267▕             throw new ProcessFailedException($this);
    268▕         }
    269▕ 
    270▕         return $this;
    271▕     }

      +17 vendor frames 

  18  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

解決方法

1.そもそもmysqldumpがないエラー

mysql-clientを入れる。

ただし、Debian10 "buster"ではmysql-clientパッケージは存在しないため、default-mysql-clientをいれる

RUN apt install -y --no-install-recommends default-mysql-client

2. Plugin caching_sha2_password could not be loadedエラー

pluginがないらしい。

debianのdefault-mysql-clientはMariaDBに統合されたようでLaravelで実行しているオプションが存在していない模様

libmariadb-devを入れる

RUN apt install -y --no-install-recommends default-mysql-client libmariadb-dev

実行

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?