やりたいこと
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
実行
参考