Created
January 6, 2021 13:39
-
-
Save rehmatworks/eeaf8fa002eef8228776a0d4e84d6c1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A very tiny Python script to dump all databases for a user as .sql files. | |
""" | |
DB_USER='' | |
DB_PASS='' | |
import os | |
import mysql.connector | |
conn = mysql.connector.connect(user=DB_USER, password=DB_PASS) | |
cursor = conn.cursor() | |
dbs = [] | |
cursor.execute('show databases') | |
for databases in cursor: | |
for database in databases: | |
try: | |
dbname = str(database) | |
print('Dumping database {} as {}.sql'.format(dbname, dbname)) | |
os.system('mysqldump {} > {}.sql'.format(dbname, dbname)) | |
except: | |
print('Database dumping failed!!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
pip install mysql-connector
python mysql-export.py
)