Skip to main content
fixed issue with code and added import
Source Link

I'm doing this on MYSQL.

It puts all the tables schema and data into their own file so I can easily see what has changed.

Unlike most of the other solutions in this thread this solution gets the data, which is important for a CMS.

This solution doesn't use any tools, just a command line script.

edit: I found my older code had a bug where import order was important. taking off the --compact flag fixes the bug.

for x in `mysql --skip-column-names -u root -ppassword dbname -e 'show tables;'`; do
     echo exporting $x
     mysqldump -u root -ppassword --skip-add-drop-table --skip-add-locks --skip-disable-keys --skip-set-charset --extended-insert=FALSE --replace --skip-dump-date dbname $x > "./db/$x.sql"
done

Older code

for x in `mysql --skip-column-names -u root -ppassword dbname -e 'show tables;'`; do
     mysqldump -u root -ppassword --compact --extended-insert=FALSE --replace dbname $x > "./db/$x.sql"
done

and here is how to import

for x in `ls ./db/*.sql`; do
     echo importing $x
     mysql -pdbpassword dbname --force < $x
done

I'm doing this on MYSQL.

It puts all the tables schema and data into their own file so I can easily see what has changed.

Unlike most of the other solutions in this thread this solution gets the data, which is important for a CMS.

for x in `mysql --skip-column-names -u root -ppassword dbname -e 'show tables;'`; do
     mysqldump -u root -ppassword --compact --extended-insert=FALSE --replace dbname $x > "./db/$x.sql"
done

I'm doing this on MYSQL.

It puts all the tables schema and data into their own file so I can easily see what has changed.

Unlike most of the other solutions in this thread this solution gets the data, which is important for a CMS.

This solution doesn't use any tools, just a command line script.

edit: I found my older code had a bug where import order was important. taking off the --compact flag fixes the bug.

for x in `mysql --skip-column-names -u root -ppassword dbname -e 'show tables;'`; do
     echo exporting $x
     mysqldump -u root -ppassword --skip-add-drop-table --skip-add-locks --skip-disable-keys --skip-set-charset --extended-insert=FALSE --replace --skip-dump-date dbname $x > "./db/$x.sql"
done

Older code

for x in `mysql --skip-column-names -u root -ppassword dbname -e 'show tables;'`; do
     mysqldump -u root -ppassword --compact --extended-insert=FALSE --replace dbname $x > "./db/$x.sql"
done

and here is how to import

for x in `ls ./db/*.sql`; do
     echo importing $x
     mysql -pdbpassword dbname --force < $x
done
Source Link

I'm doing this on MYSQL.

It puts all the tables schema and data into their own file so I can easily see what has changed.

Unlike most of the other solutions in this thread this solution gets the data, which is important for a CMS.

for x in `mysql --skip-column-names -u root -ppassword dbname -e 'show tables;'`; do
     mysqldump -u root -ppassword --compact --extended-insert=FALSE --replace dbname $x > "./db/$x.sql"
done