douwei1930
douwei1930
2015-07-22 15:24
浏览 46
已采纳

基于其他列组合的MySQL InnoDB自动增量列

I am making a system where users can upload any file they want, and not use it to execute any kind of code. As a part of that, I rename every file, and store its original name in a MySQL table. This table contains the id of the user who uploaded it, and a unique id of the upload. Currently I am doing it like this:

CREATE TABLE `uploads` (
    `user_id` INT(11) NOT NULL,
    `upload_id` INT(11) NOT NULL AUTO_INCREMENT,
    `original_name` VARCHAR(30) NOT NULL,
    `mime_type` VARCHAR(30) NOT NULL,
    `name` VARCHAR(50) NOT NULL,
    PRIMARY KEY (`user_id`, `upload_id`)
) ENGINE=MyISAM;

This means I will always have a unique combination of user_id and upload_id, and every users first upload has an id of 1. However I heard MyISAM is old, and i should rather use InnoDB. Is there any way I can achieve this in InnoDB?

图片转代码服务由CSDN问答提供 功能建议

我正在建立一个系统,用户可以上传他们想要的任何文件,而不是用它来执行任何类型的代码 。 作为其中的一部分,我重命名每个文件,并将其原始名称存储在MySQL表中。 此表包含上载它的用户的ID以及上载的唯一ID。 目前我这样做:

  CREATE TABLE`uploads`(
`user_id`INT(11)NOT NULL,
`upload_id`INT(11)NOT  NULL AUTO_INCREMENT,
`original_name` VARCHAR(30)NOT NULL,
`mime_type` VARCHAR(30)NOT NULL,
`name`VARCHAR(50)NOT NULL,
 PRIMARY KEY(`user_id`,`upload_id  `)
)ENGINE = MyISAM; 
   
 
 

这意味着我将始终拥有user_id和upload_id的唯一组合,并且每个用户首​​次上传的ID都为1 但是我听说MyISAM很老了,我宁愿使用InnoDB。 我有什么方法可以在InnoDB中实现这个目的吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzhuo2002
    douzhuo2002 2015-07-22 16:00
    已采纳

    The biggest problem with MyISAM tables is that they are not transactional. From what you say, you will only be creating records and then reading them (possibly deleting them later) but there will be little or no editing. This situation is what MyISAM was designed for, it is fast for mostly read only records. Personally I see no advantage converting to InnoDB.

    点赞 评论

相关推荐