简体   繁体   English

帮助设置MySQL数据库

[英]Help setting up MySQL Database

I need help setting up my MySQL Database. 我需要帮助设置我的MySQL数据库。

I would like the database to have a table called accounts. 我希望数据库有一个名为accounts的表。 All user accounts would be kept in that database. 所有用户帐户都将保留在该数据库中。 The user account would have the keys: 用户帐户将拥有密钥:

  • First Name 名字
  • Last Name
  • Email Address 电子邮件地址
  • Username 用户名
  • Password 密码
  • Date of Last Login. 上次登录日期。

I would really appreciate it if you could tell me what the schema should look like for it. 如果您能告诉我架构应该是什么样子,我将非常感激。

CREATE TABLE  `MyDatabase`.`accounts` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`FirstName` VARCHAR( 32 ) NOT NULL ,
`LastName` VARCHAR( 32 ) NOT NULL ,
`Email` VARCHAR( 64 ) NOT NULL ,
`Username` VARCHAR( 32 ) NOT NULL ,
`Password` CHAR( 32 ) NOT NULL ,
`LastLoginDate` DATE NOT NULL
)

This assumes you're using an MD5 hashed password (which is 32 in length). 这假设您使用的是MD5哈希密码(长度为32)。 Replace MyDatabase with your database name. 用您的数据库名称替换MyDatabase。

I think you mean user account would have these columns. 我认为你的意思是用户帐户会有这些列。 Certainly they aren't all candidate keys. 当然,它们不是所有候选键。

No account ID? 没有账号? Wouldn't that be the best unique primary key? 这不是最好的独特主键吗?

I can see where the columns you proposed would belong in a user/customer table; 我可以看到你建议的列在用户/客户表中的位置; username and password (encrypted and salted, of course) would be in a credential table. 用户名和密码(加密和加密,当然)将在凭证表中。 I wouldn't have any of these in an account table. 我不会在帐户表中有任何这些。 I'd have a foreign key pointing to the user that owned the account. 我有一个外键指向拥有该帐户的用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM