douzao1119 2015-03-19 18:00
浏览 49
已采纳

在大型MySQL数据库中用random int替换字符串的最快方法?

I have a "rather" large MySQL database (5,000,000+ records in some tables) with 7 tables that are queried using several table joins. The only problem I have is the data I am importing, some datasets have strings in the column that is being used to join the tables, and because of that, the query is incredibly slow.

What I am trying to do is replace all of these strings with random integers (making sure the int hasn't been used already), and that includes (ex. xxx_id column) keeping a record of old_xxx_id and new_xxx_id so that tables that are linked stay linked correctly when I update them.

My question is, what is the fastest way to do this? I would prefer php and MySQL but I am open to other languages/sql-databases. I have a script that works, but it replaces line-by-line and can take hours and sometimes a day or two to insert the new data into the database.

Thanks!

  • 写回答

1条回答 默认 最新

  • duankang5285 2015-03-19 18:05
    关注

    A CRC or Hash would be better than random number.

    $number =  hexdec(crc32($str));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试