Skip to content

Instantly share code, notes, and snippets.

@khanof89
Created December 15, 2020 19:15
Show Gist options
  • Save khanof89/35bacacd96eb5d99b3a78707282899c8 to your computer and use it in GitHub Desktop.
Save khanof89/35bacacd96eb5d99b3a78707282899c8 to your computer and use it in GitHub Desktop.
#!/bin/sh
tables=`mysql -hNAME_OF_YOUR_SOURCE_DB_HOST -uTYPE_YOUR_DB_USER -pTYPE_YOUR_PASSWORD -e "use NAME_OF_YOUR_SOURCE_DB_HOST; SHOW TABLES";`
for table in $tables
do
mysqldump -hNAME_OF_YOUR_SOURCE_DB_HOST -uTYPE_YOUR_DB_USER -pTYPE_YOUR_PASSWORD NAME_OF_YOUR_SOURCE_DB $table --where="1 limit 1000" > "$table".sql
done
#!/bin/sh
## Please be aware that this script will drop table from destination database and will create new
FILES=*.sql
for f in $FILES
do
NAME=`echo "$f" | cut -d'.' -f1`
EXTENSION=`echo "$f" | cut -d'.' -f2`
echo $NAME
mysql -hNAME_OF_YOUR_DESTINATION_DB_HOST -uUSERNAME_OF_DESTINATION_DATABASE -pPASSWORD_OF_DESTINATION_USER DESTINATION_DATABASE_NAME < "$NAME".sql
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment