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));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)