Save (output) MySQL query results into a text file

Posted by Damodar Bashyal on April 15, 2014

 

Today because of magento bug when I saved payment info on client's site, it replaced all payment info on database with encrypted values.

garbage encrypted text

Lucky we had copy of site on staging, so instead of fixing each field one by one from mysql command line. I ran a sql command on staging server to select only payment related fields and create a sql update command for me and save in the payment.sql file, so I can run it in live site to fix garbage looking encrypted values.

This is the command I ran on the server to spit out mysql rows and update commands.

mysql -uuser -p database -e "SELECT concat('update core_config_data set value=\'',value,'\'',' where path=\'',path,'\';') as sql_update FROM core_config_data WHERE path LIKE '%payment%'" > payment.sql

This gave me output on file like this:

update core_config_data set value='PayPal' where path='payment/payflow_advanced/partner';
update core_config_data set value='PayPal' where path='payment/payflow_advanced/vendor';
update core_config_data set value='PayPal' where path='payment/payflow_advanced/user';
update core_config_data set value='0' where path='payment/payflow_advanced/sandbox_flag';
update core_config_data set value='0' where path='payment/payflow_advanced/use_proxy';

Hope this helps someone who is in same condition as me.

magento core_config_data

 
not published on website


QR Code: Save (output) MySQL query results into a text file