Is there a way to ignore columns that don't exist on INSERT?

Your current technique seems practical enough. Just one small change.

Rather than waiting for error and then creating columns one by one, you can just export the schema, do a diff and find out all the missing columns in all the tables.

That way it would be less work.

Your gui will be capable of exporting just schema or the following switch on mysqldump will be useful to find out all the missing columns.

mysqldump --no-data -uuser -ppassword --database dbname1 > dbdump1.sql
mysqldump --no-data -uuser -ppassword --database dbname2 > dbdump2.sql

Diffing the dbdump1.sql and dbdump2.sql will give you all the differences in both the databases.


you can write a store function like that:

sf_getcolumns(table_name varchar(100))

return string contatining the filed list like this: 'field_1,field_2,field_3,...'

then create a store procedure

sp_migrite (IN src_db varchar(50), IN target_db varchar(50))

that runs trugh the tables and for each table gets the filed lists and then creates a string like

cmd = 'insert into ' || <target_db><table_name> '(' || <fileds_list> || ') SELECT' || <fileds_list> || ' FROM ' <src_db><table_name>

then execute the string for each table

Tags:

Mysql

Sql