Quasi-MySQL dump for individual columns

Quasi-MySQL dump for individual columns

There is a simple trick to copy data from individual columns from one MySQL table to another (e.g. from the development server to the production server): Use the CONCAT function to generate UPDATE statements.

In this example I would like to extract the information in the primecost column of the articles table and import it onto another server:
SELECT CONCAT (“UPDATE articles SET primecost = ‘”, primecost, “‘ WHERE sku = ‘”, sku, “‘;”) FROM articles INTO OUTFILE “primecost.sql”;
A whole series of UPDATEs then appear in the primecost.sql file:
UPDATE articles SET primecost = ’39 .49 ‘WHERE sku =’ C23125123 ‘;
UPDATE articles SET primecost = ’12 .99 ‘WHERE sku =’ M23108241 ‘;
UPDATE articles SET primecost = ’14 .99 ‘WHERE sku =’ F23987912 ‘;

I can then easily import this on the production server on the Linux console:
mysql -uwolfgang -ppassword database name <primecost.sql
As I know exactly the content of the fields primecost and sku, injection is not an issue here for once. Depending on the field content, you can also use REPLACE to escape critical characters.