I want to import and export .sql into mysql or postgres in docker container
2
docker exec -it CONTAINER /usr/bin/mysqldump -u USER -pPASSWORD DATABASE > backup.sql
docker exec -i CONTAINER /usr/bin/mysql -u USER -pPASSWORD DATABASE < backup.sql
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).
Click here to cancel reply.
2
Answers
Backupdocker
Restore backup.sql
Similarly for postgres:
dump:
load:
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).