【MySQL学习】-- 0x03 .sql 创建用户及其对应数据库
------创建数据库(略)------------
---------创建用户mysql5.6以上用insert创建用户是有问题的--------- GRANT USAGE ON *.* TO 'user01'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION; -----------授权------------- ----这里我创建了个Library数据库给user01----------- grant all privileges on Library.* to user01@localhost identified by '123456'; ---------------退出之后登陆即可----------------
由于是5.6版本mysql,所以不能用insert的方式来创建用户。
GRANT USAGE ON *.* TO 'user01'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
接下来我创建Library的表
/*出版社信息 ** */ create table Publishers (Name varchar(30), Address varchar(30), Phone varchar(10), primary key(Name)); /*书的信息 ** */ create table Books (BookID varchar(10), Title varchar(30), PublisherName varchar(30), primary key(BookID), foreign key(PublisherName) references Publishers(Name)); /*作者信息 **这里的foreign key出错 */ create table Authors (BookID varchar(10) primary key, Author varchar(30)
primary key(BookID)); /*foreign key(BookID) references Books(BookID));*/ /*借书的信息 **这里的foreign key出错 */ create table Borrowinfo (BookID varchar(10), CardID varchar(10), DateOut date, DueOut date, primary key(BookID,CardID), foreign key(BookID) references Books(BookID)); /*借阅者信息 ** */ create table Borrowers (CardID varchar(10), Name varchar(10), Address varchar(10), Phone varchar(10), primary key(CardID));
但是里面的foreign出错。。。后来才发现这是个低级错误,一个表里的外码不可能是这个表的码啊。。。