PHPMyAdmin / MySql - 添加 ID 字段并自动填充 ID 号
我有一个非常大的数据库表 - 近 2000 万条记录。
这些记录没有唯一的 ID 号。所以,我插入了新字段。
现在,我想用 ID 号填充它,从第一个 ID 号 10,000,001 开始增加 1。
仅供参考 - 我在本地计算机上使用 WAMP,并且我已经拨打了最多 5000 秒的所有最大时间,并拨打了 php.ini 和 mysql.ini 中的其他几个变量,以便首先进行上传(这需要更多时间)超过10个小时!!)。
在过去,或者使用其他数据库时,我可能会将数据导出到 Excel 中,然后生成一些文本粘贴回 phpmyadmin 中以更新记录。当处理 5K 条记录,甚至 100K 条记录时,这很好,但处理 2000 万条记录时,这似乎难以管理。
提前致谢!!
I have an extremely large database table - nearly 20 million records.
The records do not have a unique ID number. So, I've inserted the new field.
Now, I would like to populate it with ID numbers, increasing by 1, starting with the first ID number being 10,000,001.
FYI - I am using WAMP on a local machine and I've dialed all my max times upto 5000 seconds and dialed up several other variables in php.ini and mysql.ini in order to do the upload in the first place (which took more than 10 hours!!).
In the past, or with other DB's, I might have exported the data into excel and then whipped up some text to paste back into phpmyadmin to UPDATE the records. This is fine when working with 5K records, or even 100K records, but this seems unmanagable with 20 million records.
Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需在 SQL 选项卡中依次运行这两个查询即可:
MySQL 将创建 id 字段并从 10000001 开始按顺序填充。
Just run these two queries one after the other in the SQL tab:
MySQL will then create the
id
field and fill it in sequentially starting at 10000001.这在 SQL Server 中有效,也许您可以将其改编为 MySQL:
它将更新从 10000001 开始的所有 ID 行,增加 1。
我希望至少能给您一些想法。
This works in SQL Server, maybe you can adapt it to MySQL:
It will update all your ID rows starting at 10000001 increasing by 1.
I hope, at least, gives you some ideas.
您需要做的就是将列设置为 AUTO_INCRMENT,mysql 将为您对行进行编号。假设您希望将新列命名为“id”。
您可以在 phpMyAdmin 的 sql 面板中发出这些命令——只需去掉末尾的分号即可。
All you need to do is set the column to be AUTO_INCREMENT and mysql will number the rows for you. Let's say you want your new column to be named 'id'.
You can issue these commands in the sql panel of phpMyAdmin -- just leave off the semicolon at the end.