Skip to content

Instantly share code, notes, and snippets.

@stefanpejcic
Created August 10, 2025 11:42
Show Gist options
  • Select an option

  • Save stefanpejcic/19364cd554bdc07f1b407dbf52531424 to your computer and use it in GitHub Desktop.

Select an option

Save stefanpejcic/19364cd554bdc07f1b407dbf52531424 to your computer and use it in GitHub Desktop.
Export OpenPanel mysql database tables
#!/bin/bash
mysql --database=panel -e "SHOW TABLES;" -s --skip-column-names | \
while read table; do
echo "Dumping $table"
echo "SHOW CREATE TABLE \`$table\`;" >> panel_full_dump.sql
mysql --database=panel -e "SHOW CREATE TABLE \`$table\`\G" | \
grep -v '^\*\*\*' >> panel_full_dump.sql
mysql --database=panel -e "SELECT * FROM \`$table\`;" --skip-column-names | \
awk -v tbl="$table" 'BEGIN {print "INSERT INTO `" tbl "` VALUES"} \
{printf "("; for(i=1; i<=NF; i++) { printf "\"%s\"", $i; if(i<NF) printf ","; } print "),"} END {print ";"}' >> panel_full_dump.sql
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment