这一部分是NBA投票系统中MySql数据库的设计,先看下这段代码
其实使用Redis会更好,以后会专门开一个版块来介绍Redis。
drop database NBATeam;
drop database NBAPlayer;
create database NBATeam;
use NBATeam;
create table NBAChampionTeam(
teamId int unsigned not null primary key,
teamName char(30),
teamVotes int unsigned);
insert into NBAChampionTeam values
(1,"Cleveland Cavaliers",0),
(2,"Golden State Warriors",0);
create database NBAPlayer;
use NBAPlayer;
create table NBABestPlayer(
teamId int unsigned not null,
playerName varchar(30),
playerVotes int);
insert into NBABestPlayer values
(1,"LeBron James",0),
(1,"Kyrie Irving",0),
(1,"Kevin Love",0),
(2,"Kevin Durant",0),
(2,"Stephen Curry",0),
(2,"Klay Thompson",0);
grant all privileges
on NBATeam.*
to NBA@localhost
identified by 'NBA';
grant all privileges
on NBAPlayer.*
to NBA@localhost
identified by 'NBA';
下面我们来进入这个数据库看看实际效果:
1、使用脚本中Grant开辟的数据库用户名,密码来进行登录,并查看该用户是否可以看到新建的数据库:
2、查看NBATeam数据库的结构:
3、查看NBATeam数据库当前投票情况:
4、查看NBAPlayer数据库的情况:
5、显示NBAPlayer中表的数据情况: