-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdb_mysql.sql
More file actions
55 lines (49 loc) · 1.68 KB
/
db_mysql.sql
File metadata and controls
55 lines (49 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- Note: only for mysql 5.7 option IF EXISTS is available, for older mysql
-- solution: https://stackoverflow.com/questions/598190/mysql-check-if-the-user-exists-and-drop-it
GRANT USAGE ON *.* TO 'nopermuser'@'localhost' identified by 'password';
DROP USER 'nopermuser'@'localhost';
CREATE USER 'nopermuser'@'localhost'
identified by 'password';
FLUSH PRIVILEGES;
DROP TABLE IF EXISTS `people`;
DROP TABLE IF EXISTS `animal`;
DROP TABLE IF EXISTS `tbl_users`;
DROP TABLE IF EXISTS `tbl_eyes`;
CREATE TABLE `people` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL DEFAULT '0',
`nickname` VARCHAR(255) NULL DEFAULT '0',
`age` INT NOT NULL DEFAULT '0',
`awesome` TINYINT(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
INDEX `awesome` (`awesome`)
)
COLLATE = 'latin1_swedish_ci';
CREATE TABLE `animal` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL DEFAULT '0',
`number_of_legs` INT NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
)
COLLATE = 'latin1_swedish_ci';
CREATE TABLE `tbl_eyes` (
`id` INT NOT NULL AUTO_INCREMENT,
`color` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY (`color`)
)
COLLATE = 'utf8_general_ci'
ENGINE = InnoDB;
CREATE TABLE `tbl_users` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`_eyeId` INT NOT NULL,
`age` INT NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `idx_eye` (`_eyeId`),
CONSTRAINT `FK_EyeId` FOREIGN KEY (`_eyeId`) REFERENCES `tbl_eyes` (`id`)
ON DELETE RESTRICT
ON UPDATE RESTRICT
)
COLLATE = 'utf8_general_ci'
ENGINE = InnoDB;