0

I've a big amont names for putting into mysql.

update tbl set value='value1' where code='123';
update tbl set value='value2' where code='124';
.... and an half milion lines

That takes too long time. Is there some quicker posibility for updating names? Thank you

user2301515
  • 4,903
  • 6
  • 30
  • 46
  • 2
    Where do the names come from? Are they already in the DB? Is it a CSV file? – juergen d Mar 05 '19 at 12:01
  • use loop to update multiple records. – Gufran Hasan Mar 05 '19 at 12:01
  • 1
    @GufranHasan: Absolutely not. – juergen d Mar 05 '19 at 12:02
  • Already asked here: https://stackoverflow.com/a/25674827/5026957 – HarisH Sharma Mar 05 '19 at 12:02
  • @harishsharma: With 500k values? – juergen d Mar 05 '19 at 12:03
  • then you can group data where value is same but code is different, Or run queries in chunk, – HarisH Sharma Mar 05 '19 at 12:05
  • I used the loop. In such case i have wait 2 days. – user2301515 Mar 05 '19 at 12:06
  • `update tbl set value='value1' where value!='value1' AND code='123';` use this, may be it will save your time, Don't use loop, You can create query inside loop with a logic that, if same value need to update in multiple code, then use mysql's IN, better than write multiple queries for them, – HarisH Sharma Mar 05 '19 at 12:12
  • You haven't said how long it is actually taking or what you've done to try to resolve it. So let's go to first principles: First thing if your queries are taking too long (even if there's a lot of them) is to make sure the database is properly indexed. Do you have an index on the `code` field? If not, add one and you will see an orders-of-magnitude speed improvement. – Spudley Mar 05 '19 at 12:19

0 Answers0