Vi Nguyen's Dev Notes
  • 📓Dev Notes
    • Buy me a coffee
  • Deployment & Operation
    • Docker Container
      • Add User to Docker Group
      • Clean up unused docker images
      • Backup Container
      • Truncate docker log
    • Git
    • Ansible
      • Ansible - Setup fresh new ubuntu server
      • Run Ansible Playbook on MacOS
    • Linux
      • Zip file with Gzip
      • Linux - add user to sudo group
      • Rsync - copy file on remote server to local
      • Tunnel all docker ports on remote server to localhost
      • Create linux Swapfile
      • Rename a file to folder name
      • Copy and keep permission on linux
    • Database
      • Check if database is reachable with nc
      • PostgreSQL
        • PostgreSQL - Create a new primary key auto-increment column
        • Generate uuid for all records in a table PostgreSQL
        • Backup & Import all database PostgreSQL Inside Docker Container
        • Backup & Import single database PostgreSQL Inside Docker Container
        • PostgreSQL - Create user & grant permission on a database
        • PostgeSQL - Backup database via remote ssh server
      • Mysql
        • Mysql - Create user & grant permission on a database
        • Dump & import Mysql database inside container
        • Mysql - Dump all Mysql database from Mysql
    • Ngnix
      • Nginx - 504 Gateway Timeout error using Nginx as Proxy
      • Download file from server via nginx docker
  • Docker-compose samples
    • docker-compose - n8n
    • docker-compose - PostgreSQL
    • docker-compose caddy as reverse proxy
  • Homelab
    • Rasberry Pi 4B - Bookworm HDMI config
    • Waveshare 3.5" display on Pi 4 -Bookworm 64 Bit
  • Development
    • Development Notes
  • My Resources
    • Blog
    • Geek Tools
    • Dev Note Github Repo
Powered by GitBook
On this page
  1. Deployment & Operation
  2. Database
  3. Mysql

Mysql - Dump all Mysql database from Mysql

Dump all databases from Mysql

USER="your_username"
PASSWORD="your_password"
#OUTPUT="/Users/rabino/DBs"

#rm "$OUTPUTDIR/*gz" > /dev/null 2>&1

databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`

for db in $databases; do
    if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
        echo "Dumping database: $db"
        mysqldump -u $USER -p$PASSWORD --databases $db > `date +%Y%m%d`.$db.sql
       # gzip $OUTPUT/`date +%Y%m%d`.$db.sql
    fi
done

Last updated 1 year ago