0
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 3 years have passed since last update.

MacからDockerのMySQLにgzip圧縮のダンプを流すコマンド

Last updated at Posted at 2021-10-23

なぜこの記事を書いたか

Macだとzcatじゃなくてgzcatだよっていう話と、
mysqlのpオプションをパイプで使うと怒られるよっていうのを忘れないため。

前提

  • ディレクトリなどの名称は仮称

コマンド

流す対象のDBやユーザをまだ作ってなければ作成する

$ mysql -p -h 127.0.0.1
> CREATE DATABASE sample CHARACTER SET utf8mb4;
> GRANT ALL ON *.* TO 'admin'@'%' WITH GRANT OPTION;
> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin';
> CREATE USER 'admin'@'127.0.0.1' IDENTIFIED BY 'admin';
> FLUSH PRIVILEGES;

ダンプを流し込む

$ export MYSQL_PWD=admin
$ gzcat ./infra/mysql/dump/sample.dump.gz | mysql -u admin -h 127.0.0.1 sample

ちなみにS3から流す場合

S3にあるのが生データならこう

$ export MYSQL_PWD=admin
$ aws s3 cp s3://バケット名/dump/20211023/sample.sql - | mysql -u admin -h 127.0.0.1 sample

S3にあるのがgzipならたぶんこう

$ export MYSQL_PWD=admin
$ aws s3 cp s3://バケット名/dump/20211023/sample.sql.gz - | gzcat | mysql -u admin -h 127.0.0.1 sample
0
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
0
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?