使用Python备份mysql

#!/usr/bin/env python
import osimport time

username = root  
password = 123456  
hostname = localhost

filestamp = time.strftime('%Y-%m-%d')

database_list_command="mysql -u %s -p%s -h %s --silent -N -e 'show databases'" % (username, password, hostname)for database in os.popen(database_list_command).readlines():  
database = database.strip()  
if database == 'information_schema':  
    continue
    filename = "/backups/mysql/%s-%s.sql" % (database, filestamp)
    os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" % (username, password, hostname, database, filename))

Grizzly

Never say never!