Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a MYSQL DB and I need to do some text manipulation on one of the fields. This is a one-off, not an ongoing process.

The built in MySQL text manipulation functions will be a nightmare to do what I need to do. Perl can do it in a few lines, and I even have a perl script hanging aorund with the exact text manipulation commands needed.

Dumping the table to a text file, Perling it, and then restoring it would work but is a bit cumbersome; is there an easier or better way to use perl to manipulate the data within the mysql DB to cycle through each row in the table, edit the data in a field, and move on the the next row?

share|improve this question

2 Answers 2

You can use the DBI module with the DBD::mysql driver to access the database for reading and writing, and just loop through the rows you're interested in. The documentation should be enough to give you a decent start, but it could be a good idea to back things up before you break stuff.

share|improve this answer

The best method would be to modify the data "in place" using Perl's MySQL DBI.

SELECT the data, perform the regex and send it back with an UPDATE.

My personal preference would be to use Python, with it's MySQLdb and re modules.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.