Skip to content

Instantly share code, notes, and snippets.

@hugowetterberg
Created February 24, 2010 10:49
Show Gist options
  • Save hugowetterberg/313324 to your computer and use it in GitHub Desktop.
Save hugowetterberg/313324 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()
@aremongallego
Copy link

It has been very useful, just what I needed. Thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment