Docker 中 MySQL 数据的导入导出

Creating database dumps

Most of the normal tools will work, although their usage might be a little convoluted in some cases to ensure they have access to the mysqld server. A simple way to ensure this is to use docker exec and run the tool from the same container, similar to the following:

$ docker exec some-mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql

Restoring data from dump files

For restoring data. You can use docker exec command with -i flag, similar to the following:

$ docker exec -i some-mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' < /some/path/on/your/host/all-databases.sql

出处:https://hub.docker.com/_/mysql?tab=description

posted on 2019-07-08 10:49  cag2050  阅读(466)  评论(0编辑  收藏  举报

导航