> For the complete documentation index, see [llms.txt](https://dev-notes.vinguyen.blog/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev-notes.vinguyen.blog/notes/deployment-and-operation/database/mysql/dump-and-import-mysql-database-inside-container.md).

# Dump & import Mysql database inside container

```bash
# backup

MYSQL_CONTAINER=$(docker ps --filter ancestor=mysql:5.7 -q)
docker exec $MYSQL_CONTAINER /usr/bin/mysqldump -u root --password=your_db_password your_backup_db | gzip > your_backup_db.$(date +%F.%H%M%S).sql.gz


# Restore
cat your_backup_db.sql | docker exec -i $MYSQL_CONTAINER /usr/bin/mysql -u your_db_username --password=your_db_password your_target_db
```
