I want to import and export .sql into mysql or postgres in docker container
CodePudding user response:
Backupdocker
docker exec -it CONTAINER /usr/bin/mysqldump -u USER -pPASSWORD DATABASE > backup.sql
Restore backup.sql
docker exec -i CONTAINER /usr/bin/mysql -u USER -pPASSWORD DATABASE < backup.sql
CodePudding user response:
Similarly for postgres:
dump:
docker exec -it CONTAINER /usr/bin/pg_dump -U USER DATABASE > backup.sql
load:
docker exec -i CONTAINER /usr/bin/psql -U USER DATABASE < backup.sql
That is for a single database. If you want to do this for all databases and global objects, use pg_dumpall instead.
For a user with a password, you'll want to set up the password non-interactively (e.g., with PGPASSWORD).