Domanda

I have a text file with 67,000 rows and each row is an update statement.

is it possible to execute all of the update statements at once? or what tool can I use to do this in MySQL?

The data or the columns being updated changes for most of them.

Here are a couple of samples that have for the update.

UPDATE emailTbl SET  CC="", BCC="", recipient_new="someone@domain.com" WHERE docid=0000000139;        
UPDATE emailTbl SET  CC="", BCC="", recipient_new="someone2@domain.com" WHERE docid=0000000362;        
UPDATE emailTbl SET sender_new="aperson@domain.com", CC="", BCC="", recipient_new="anotheruser@domain.com" WHERE docid=0000004313;        
È stato utile?

Soluzione 2

You don't say whether you are using an InnoDB or a MyISAM table. It matters, because InnoDB supports transactions. You can get this to run much faster on InnoDB by adding an occasional transaction line to your text file.

The file should ideally look like this:

  START TRANSACTION;
  UPDATE emailTbl SET  CC="", BCC="", recipient_new="someone@domain.com" WHERE docid=0000000139;
  UPDATE emailTbl SET blah blah blah;
  UPDATE emailTbl SET blah blah blah;
  ...97 more UPDATE lines ... 
  COMMIT;
  START TRANSACTION;
  UPDATE emailTbl SET blah blah blah;
  ...99 more UPDATE lines ... 
  COMMIT;
  START TRANSACTION;
  UPDATE emailTbl SET blah blah blah;
  ...99 more UPDATE lines ... 
  COMMIT;

In other words, begin your file with START TRANSACTION;. End it with COMMIT;. Every hundred lines or so insert these two lines to finish up one transaction and start another.

  COMMIT;
  START TRANSACTION;

If you don't do this, your command line mysql client will run in autocommit mode, which will make it take a lot longer to chew through all these updates; it will do a commit for each row.

If you run mysql with autocommit mode turned off, it will try to do all 67 kilorows in a single transaction. You may fill up your server's commit buffer RAM.

Altri suggerimenti

This is supported using the mysql command-line tool.

The statements are executed sequentially. I do not know of any tools that do this in parallel, nor am I sure that's a good idea.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top