snippetsqlMinor
How to change data structure in mysql using mysqldump without deleting files
Viewed 0 times
withoutdeletingmysqldumpmysqlfilesstructureusinghowdatachange
Problem
Essentially what I'm trying to do is sync a production server with a sandbox server, but only the table structures and stored procedures. The procedures aren't any problem since they can be overriden, but the problem is the tables. I want to sync and alter their structures on the production server using
If it helps, I only want to add more columns, not remove any existing ones. Also, I am using
Is there any way to do this?
mysqldump (or any other way that you can propose) without altering any existing data.If it helps, I only want to add more columns, not remove any existing ones. Also, I am using
mysqlyog.Is there any way to do this?
Solution
As long as you don't rename tables and columns and you are not using partitions you might use schemasync .
Basic usage is:
This will produce two SQL scripts - one for "patching" the production database, and another one for reverting the changes.
Please note that schema altering will lock the tables being affected, so you will have some downtime anyway. There are tools to avoid this: pt-online-schema-change from Percona and oak-online-alter-table from openarkkit.
Also, as with any possibly destructive changes, test the procedure on a staging (or other non-production use, but production data and schema) database.
Basic usage is:
schemasync mysql://user:pass@dev-host:3306/dev_db mysql://user:pass@prod-host:3306/prod_dbThis will produce two SQL scripts - one for "patching" the production database, and another one for reverting the changes.
Please note that schema altering will lock the tables being affected, so you will have some downtime anyway. There are tools to avoid this: pt-online-schema-change from Percona and oak-online-alter-table from openarkkit.
Also, as with any possibly destructive changes, test the procedure on a staging (or other non-production use, but production data and schema) database.
Code Snippets
schemasync mysql://user:pass@dev-host:3306/dev_db mysql://user:pass@prod-host:3306/prod_dbContext
StackExchange Database Administrators Q#27235, answer score: 5
Revisions (0)
No revisions yet.