Export mysql databases of XAMPP


The script exports all databases of xampp's mysql in individual files. All sql files will be saved in the directory /tmp/db but you can define your desired path.

If you have username and password of the mysql, enter your mysql username in place of text root and your password between the inverted commas. Do not remove the inverted commas. Put your password inside it.

When script runs, if it prompts for mysql password, do not enter anything, just press return key.


#!/bin/bash
#Take back up of all databases of XAMPP's mysql

############### variables ###############
bu_path=/tmp/db

#########################################

mkdir "$bu_path"
IFS=$'\n'
lst=$(sudo /opt/lampp/bin/mysql -e 'show databases' | grep -iv "database" | sort;)
for i in $lst
do
sudo /opt/lampp/bin/mysqldump "$i" > "$bu_path/$i.sql"
echo "$i exported successfully"
done


Save the code in the text file and save as export.sh
Now give the executing permission to the script 
# chmod a+x /path/of/export.sh
Now run the script.
# cd /path/to/the/directory 

# ./export.sh

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...