Skip to content

Instantly share code, notes, and snippets.

@CmdrMahesh
Forked from hugowetterberg/dumpdatabases.py
Created November 17, 2019 13:37
Show Gist options
  • Save CmdrMahesh/2f95dd7bd30283da390ce8a869bcd7c0 to your computer and use it in GitHub Desktop.
Save CmdrMahesh/2f95dd7bd30283da390ce8a869bcd7c0 to your computer and use it in GitHub Desktop.
Small script to dump all local mysql databases
#!/usr/bin/env python
import os
import re
import subprocess
user="onlyme"
password="xxxxxxx"
proc = subprocess.Popen(["mysql", "-u" + user, "-p" + password],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr = subprocess.PIPE)
output, errors = proc.communicate("SHOW DATABASES")
for database in output.splitlines()[1:]:
if database != 'information_schema':
print "Dumping %s" % database
file = open("%s.sql" % database, 'w')
proc = subprocess.Popen(["mysqldump", "-u" + user, "-p" + password, database],
stdout=file)
proc.communicate()
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment