skip to Main Content

I want to import and export .sql into mysql or postgres in docker container

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search