Reputation: 2350
I'm working with a database in a development environment in MySQL Workbench. I have everything ready to go and need to move it to a prod database. I've exported it to a sql file but I'm unsure if I'm approaching the import the correct way.
If I use the "Data Import/Restore" feature, select my SQL file, and import, will it replace the existing data in the database (what I want to happen) or will it add new records to each table for the new data?
The schema is the same in each database. I just need to replace the old data in the prod database with the new data from dev.
Thanks for your help
Upvotes: 3
Views: 11755
Reputation: 299
You can use MySQL specific replace
statement to achieve this goal. check out this link
Upvotes: 0
Reputation: 1120
That depends on how your export-file looks. Just open it in a text editor and read over the statements in your export-file.
By default it should contain statements like:
CREATE TABLE IF NOT EXISTS `customer` (
`CUSTOMER_ID` int(11) NOT NULL,
`CUSTOMER_NM` varchar(100) DEFAULT ''
) EN
and right after it the data of this table:
INSERT INTO `customer` (`CUSTOMER_ID`, `CUSTOMER_NM`) VALUES
(0, 'Dummy Customer');
(1, 'Dummy Two');
Since your tables already exist in your PROD-Environment it will not delete, create or replace them (Note the CREATE TABLE IF NOT EXISTS
-Statement). The INSERT
-Stamement will be executed (there is no condition which says it shouldn't).
So after importing your file you will have your previous PROD-Data in your database + the imported DEV-Data your your DEV-Environment.
On the other hand it could contain a statement like:
DROP TABLE IF EXISTS `customer`
And right after it the CREATE
-Statement followed by some INSERT
-Statements. In this case your whole PROD
-Database will be replaced by the DEV-Database as you want it to.
Upvotes: 4