mySQL多维(多用户)

标签 mysql database-design

我是 mySQL 和数据库设计的新手。我认为我之前的解释尝试很困惑,所以这里有一张图片可以提供帮助:

enter image description here

我有一个 mySQL 数据库。不同的用户需要访问数据库,当他们登录时,特定于他们的存储信息将被加载到 n x m (6 x 7) 表中。此外,他们可以选择他们想要查看的“月份”,每个月本质上都是加载到 6 x 7 View 中的不同数据。

问题:

1) 每个用户是否有不同的数据库(可能有 1000 个),或者如果只有一个数据库,我该如何安排/管理用户/数据访问?

2)我如何管理/构建“月份”或Z维度,因为我的理解是mySQL是平面数组。

谢谢。

[忽略我下面笨拙的解释]

The requirement I have is to have an n x m table where n is a date entry and m may be 1 to nth columns containing data about a user specific to that date - weather, food, clothes. However, I then want this format/table for 1 to nth users, so each user has there own page

So for user 1 the table may look like:

06-04-15; sunny; apple; jeans
07-04-15; rainy; orange; coat
08-04-15; snow; mango; vest
 for user 2 the table may look like:

03-04-15; sunny; apple; jeans
04-04-15; rainy; orange; coat
05-04-15; snow; mango; vest
06-04-15; wind; apple; hat
07-04-15; dry; bread; scarf
08-04-15; snow; mango; vest

1) I wondered if this is kind of structure is possible?

2) and whether it is the recommended way of structuring a user database of this type?

3) Furthermore, the database rows may be growing more one user instance, but not all users equally, would this cause problems?

Any examples, tutorials or code snippets would be welcomed.

最佳答案

不可能在同一行中存储多个值。

虽然您可以将数据捆绑到您自己的数据结构中,而这对 DBMS 来说是不透明的,但这是非常糟糕的做法。拥有多个具有相同结构的表也是非常糟糕的做法。

您可以简单地通过使用多行来表示每条记录来表示数据:

CREATE table multid (
   userid integer,
   rdate date,
   value varchar(20)
   PRIMARY KEY (userid, rdate, value)
);

然后您可以按照您想要的格式提取数据:

SELECT rdate, GROUP_CONCAT(value SEPARATOR ';')
FROM multid
WHERE userid='user 1'
GROUP BY rdate;

关于mySQL多维(多用户),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29492777/

相关文章:

mysql - MySQL系统数据库表可以转换为InnoDB吗?

PHP MySQL 使用变量进行查询

javascript - 打印 MySQL SUM() 函数的 json_encode

mysql - 照片关键字和数据库 - 哪种实现?

mongodb - 以下和提要的mongodb设计,我应该在哪里嵌入?

mysql - 数据库中的一对一关系

mysql - 当关系是非标识时从多个表中删除

php - 升级 PHP 分页功能以使其运行速度更快

database - 如果我们每毫秒生成一个数字,那么一天会有多少数据?

sql - 如何在记录更改时更新不同位置(表)的多个信息?