用户登录表

create user 'BioCotton'@'localhost' identified by '密码'; BioCotton39558728cotton@
## root权限下新建数据库
create database bioinformatic character set utf8;
## 赋予权限
grant all privileges on bioinformatic.* to 'BioCotton'@'localhost';

最简单的表结构开始

  1. id

  2. userName

  3. password

1.mysql中创建对应的表结构

use bioinformatic;
CREATE TABLE IF NOT EXISTS user(
  id int not NULL COMMENT '用户ID'  auto_increment,
  name  VARCHAR(20) not NULL ,
  password VARCHAR(32) not NULL,
  PRIMARY KEY(id),
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

查看表结构

describe user

2.添加新的用户

INSERT INTO user(name,password) VALUES('zpliu',md5('123456'));

由于id字段是自动往上加的,所以添加的时候可以不填

创建外键约束

  • 加上真实姓名

插入数据

外键关联查询

使用左连接

左连接是把左边的表作为主表,完全显示;右连接是把右边的表作为主表,完全显示。

而内连接(inner join或者join)只显示两张表中都能对应的数据

参考

mysql外键约束 https://blog.csdn.net/lvtula/article/details/81940429

Last updated

Was this helpful?