mysql> desc oldtable;
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| uid | int(11) | NO | PRI | NULL | auto_increment |
| active | char(1) | NO | | NULL | |
| field3 | char(256) | NO | | NULL | |
| field4 | char(256) | NO | | NULL | |
+---------------+--------------+------+-----+---------+----------------+
mysql> desc newtable;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| uid | int(11) | NO | PRI | NULL | auto_increment |
| active | tinyint(1) | NO | | 0 | |
| field5 | int(12) | NO | | 0 | |
| field6 | varchar(12) | NO | | 0 | |
| field7 | varchar(12) | NO | | 0 | |
+------------+--------------+------+-----+---------+----------------+
This is similar to my previous query change a field and port mysql table data via script ?
[I would like to port data (dump) from oldtable into newtable. One issue is, earlier the table used char(1) for active which stores value either ‘Y’ or ‘N’. Now the newtable stores it as int either 1 or 0.
How can i fix this before porting data? Should I use shell script for such fix & porting ? Any sample scripts or tips :)]
But this question, How to achieve the same porting,If both tables has different no.of fields
like above?
The answer is similar to the previus question answer:
Then update newTable with new fields values:
Also, you can define new fields as null allowed and leave this fields without value.