php-文件管理器数据库设计(mysql)
有关图像的信息(宽度/高度)是不相关的。如果我需要,我会将其放在另一个表中,但我不需要图像信息。您觉得这个数据库设计怎么样?您对特定表的 MyISAM 与 InnoDB 有何看法?
谢谢,我很感激任何反馈。
DROP TABLE IF EXISTS `directory`;
CREATE TABLE `directory` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`parent_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `file`;
CREATE TABLE `file` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`fk_directory_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `tag`;
CREATE TABLE `tag` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `tags_files`;
CREATE TABLE `tags_files` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fk_file_id` int(11) DEFAULT NULL,
`fk_tag_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Info about images (width/height) are irrelevant. If i need that i'll put it in another table but i don't need images info. What do you think about this db design? What do you think about MyISAM vs InnoDB for specific tables?
Thank you, I appreciate any feedback.
DROP TABLE IF EXISTS `directory`;
CREATE TABLE `directory` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`parent_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `file`;
CREATE TABLE `file` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`fk_directory_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `tag`;
CREATE TABLE `tag` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `tags_files`;
CREATE TABLE `tags_files` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fk_file_id` int(11) DEFAULT NULL,
`fk_tag_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
列
name
应该是唯一的并且该列不应该使用
utf8_unicide_ci
,由于区分大小写,例如,在linux中(不在窗口中)
example.jpg != example.JPG
使用ci会导致唯一名称问题
如果需要大量写入,innodb应该更合适
其他图像的附加信息(如宽度、高度)可以存储到表中,以便于搜索/过滤
不太可能希望保留文件的版本,但您应该存储有关创建者的信息(例如 user_id),因此,您可以轻松追溯信息
column
name
should be uniqueand it should not using
utf8_unicide_ci
for this column, due to case sensitives,for example, in linux (not in window)
example.jpg != example.JPG
using ci will cause the unique name problem
if you require lots of write, innodb should be more appropriate
other images additional info like, width, height can be stored into table in order to facility search/filter
unlikely you would like to keep versions of the file, but you should store the information about creator (like user_id), so, you can trace back information easily
由于只有“ajreal”回答了这个问题,我决定我的数据库设计的基础将是我建议的数据库设计。感谢 ajreal 的回答(投票:))。我知道,ajreal,关于存储所有附加信息(用户、权限、acl、图像大小……以及所有其他应该存储的“小信息”:)我只是想听听其他意见)。谢谢。
Since only "ajreal" answered this question i decided that base for my db design will be db design i suggested. Thanks ajreal for the answer(voteup:)). I know, ajreal, about storing all additional info(users, rights, acl, image sizes, ... and all the rest "small infos" that should be stored:) i just wanted to hear another opinions). Thanks.