开发者

Login storage suggestions

I'm looking to log all logins by a user. Something Simple like userid, date, ipshou开发者_StackOverflowld I just create a database with each table being a user followed by each row being a login? If there were 100's of users would there be any negative effects of such a method? Is this the way it's done in practice? or is there a better way?


Do not create a separate table for each user. The table should encompass all logins by all users:

CREATE TABLE logins (
    id INT NOT NULL AUTO_INCREMENT, 
    user_id INT UNSIGNED NOT NULL,
    log_time DATETIME, 
    ip INT UNSIGNED,
    PRIMARY KEY (id)
);

mysql> DESCRIBE logins;
+----------+------------------+------+-----+---------+----------------+
| Field    | Type             | Null | Key | Default | Extra          |
+----------+------------------+------+-----+---------+----------------+
| id       | int(11)          | NO   | PRI | NULL    | auto_increment |
| user_id  | int(11)          | NO   |     | NULL    |                |
| log_time | datetime         | YES  |     | NULL    |                |
| ip       | int(10) unsigned | YES  |     | NULL    |                |
+----------+------------------+------+-----+---------+----------------+
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜