-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mysql Pr19
264 lines (216 loc) · 12.5 KB
/
Mysql Pr19
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
--
-- Database: `school_database`
--
-- --------------------------------------------------------
--
-- Table structure for table `absences`
--
DROP TABLE IF EXISTS `absences`;
CREATE TABLE IF NOT EXISTS `absences` (
`student_id` int(10) UNSIGNED NOT NULL,
`date` date NOT NULL,
PRIMARY KEY (`student_id`,`date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `classes`
--
DROP TABLE IF EXISTS `classes`;
CREATE TABLE IF NOT EXISTS `classes` (
`name` varchar(30) NOT NULL,
`class_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`class_id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;
--
-- Dumping data for table `classes`
--
INSERT INTO `classes` (`name`, `class_id`) VALUES
('English', 1),
('Calculus', 7),
('Biology', 9),
('Chemistry', 10),
('Physics', 11),
('History', 12),
('Art', 13),
('Gym', 14);
-- --------------------------------------------------------
--
-- Table structure for table `scores`
--
DROP TABLE IF EXISTS `scores`;
CREATE TABLE IF NOT EXISTS `scores` (
`student_id` int(10) UNSIGNED NOT NULL,
`test_id` int(10) UNSIGNED NOT NULL,
`score` int(11) NOT NULL,
PRIMARY KEY (`test_id`,`student_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `students`
--
DROP TABLE IF EXISTS `students`;
CREATE TABLE IF NOT EXISTS `students` (
`first_name` varchar(30) NOT NULL,
`last_name` varchar(30) NOT NULL,
`email` varchar(60) DEFAULT NULL,
`street_name` varchar(30) NOT NULL,
`street_type` varchar(10) NOT NULL,
`city` varchar(40) NOT NULL,
`province` varchar(2) DEFAULT NULL,
`postal_code` varchar(8) NOT NULL,
`phone` varchar(20) NOT NULL,
`dob_day` int(11) NOT NULL,
`dob_month` varchar(10) NOT NULL,
`dob_year` int(11) NOT NULL,
`gender` enum('M','F','Oth') NOT NULL,
`date_entered` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`course` varchar(15) NOT NULL,
`student_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`student_id`)
) ENGINE=InnoDB AUTO_INCREMENT=141 DEFAULT CHARSET=utf8;
--
-- Dumping data for table `students`
--
INSERT INTO `students` (`first_name`, `last_name`, `email`, `street_name`, `street_type`, `city`, `province`, `postal_code`, `phone`, `dob_day`, `dob_month`, `dob_year`, `gender`, `date_entered`, `course`, `student_id`) VALUES
('Aa', 'Aa', '[email protected]', 'Aaaa', 'Ave', 'Aaaa', 'AB', 'A1A 1A1', '(905) 111-1111', 1, 'JAN', 1990, 'M', '2016-06-09 20:24:35', 'PLF4M & IDP4U', 107),
('Zz', 'Zz', '[email protected]', 'Zzzz', 'Sq', 'Toronto', 'ON', 'L8J 3P9', '(905) 342-9983', 31, 'DEC', 2005, 'M', '2016-06-09 20:25:39', 'PAD2O1', 108),
('Bobby', 'Joester', '[email protected]', 'Ruralave', 'Pkwy', 'Oakville', 'ON', 'L9C 4B9', '(905) 728-2891', 14, 'AUG', 2004, 'Oth', '2016-06-09 23:39:37', 'PAD3O1', 112),
('Jane', 'Miller', '[email protected]', 'Treetop', 'Crcl', 'Lonetown', 'ON', 'L8D 3P9', '(905) 762-9103', 14, 'SEP', 1994, 'F', '2016-06-10 20:59:05', 'PAD2O1', 121),
('Denise', 'Stewart', '[email protected]', 'Municipality', 'Hts', 'Township', 'PE', 'L9C 4K6', '(905) 592-9172', 16, 'OCT', 1996, 'F', '2016-06-10 21:00:36', 'PAD3O1', 123),
('Cynthia', 'Brown', '[email protected]', 'Korner', 'Pl', 'Porous', 'PE', 'L7S 4H7', '(905) 592-9172', 16, 'OCT', 1996, 'F', '2016-06-10 21:01:51', 'PAD2O1', 124),
('Mark', 'Jones', '[email protected]', 'Wentworth', 'Crct', 'Urapean', 'ON', 'L9C 8Y9', '(905) 728-2891', 14, 'SEP', 2003, 'M', '2016-06-10 21:04:07', 'PAD3O1', 126),
('Ernest', 'Hemingway', '[email protected]', 'Writer', 'Sq', 'Hamilton', 'ON', 'L8J 3P9', '(905) 342-9983', 16, 'OCT', 2005, 'M', '2016-06-10 21:05:25', 'PAD2O1', 127),
('Mark', 'Twain', '[email protected]', 'Author', 'Dr', 'West-15th', 'AB', 'L9C 4B9', '(905) 574-1712', 14, 'OCT', 2003, 'M', '2016-06-10 21:06:00', 'PAD3O1', 128),
('Jane', 'Austen', '[email protected]', 'Block', 'Cres', 'Toronto', 'ON', 'L7C 4M8', '(905) 342-9983', 11, 'JAN', 2003, 'F', '2016-06-10 21:06:51', 'PAD3O1', 129),
('James', 'Markinham', '[email protected]', 'Just', 'Ave', 'Nowhere', 'ON', 'L8D 3P9', '(905) 762-9103', 17, 'SEP', 1996, 'M', '2016-06-10 21:11:09', 'PAD2O1', 131),
('Simeng', 'Yang', '[email protected]', 'Somewherest', 'Blvd', 'Hamilton', 'ON', 'L9C 4B9', '(905) 574-1712', 17, 'MAR', 1998, 'M', '2016-06-12 22:34:15', 'PAD3O1', 138);
-- --------------------------------------------------------
--
-- Table structure for table `tests`
--
DROP TABLE IF EXISTS `tests`;
CREATE TABLE IF NOT EXISTS `tests` (
`date` date NOT NULL,
`type` enum('T','Q') NOT NULL,
`maxscore` int(11) NOT NULL,
`class_id` int(10) UNSIGNED NOT NULL,
`test_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`test_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `user_account`
--
DROP TABLE IF EXISTS `user_account`;
CREATE TABLE IF NOT EXISTS `user_account` (
`userID` int(9) NOT NULL AUTO_INCREMENT,
`userName` varchar(40) NOT NULL,
`pass` varchar(40) NOT NULL,
PRIMARY KEY (`userID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
--
-- Dumping data for table `user_account`
--
INSERT INTO `user_account` (`userID`, `userName`, `pass`) VALUES
(1, 'root', 'password');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- phpMyAdmin SQL Dump
-- version 4.5.2
--
-- Host: 127.0.0.1
-- Generation Time: Jun 13, 2016 at 12:08 AM
-- Server version: 5.7.12-log
-- PHP Version: 5.6.16
--
-- Author: Simeng Yang
-- https://github.com/simeng-yang/Student-Database-Management-System/blob/master/%5BExported%5D%20school_database.sql
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
mysql> select * from world.students;
+------------+-----------+---------------------+--------------+-------------+-----------+----------+-------------+----------------+---------+-----------+----------+--------+---------------------+---------------+------------+
| first_name | last_name | email | street_name | street_type | city | province | postal_code | phone | dob_day | dob_month | dob_year | gender | date_entered | course | student_id |
+------------+-----------+---------------------+--------------+-------------+-----------+----------+-------------+----------------+---------+-----------+----------+--------+---------------------+---------------+------------+
| Aa | Aa | [email protected] | Aaaa | Ave | Aaaa | AB | A1A 1A1 | (905) 111-1111 | 1 | JAN | 1990 | M | 2016-06-09 20:24:35 | PLF4M & IDP4U | 107 |
| Zz | Zz | [email protected] | Zzzz | Sq | Toronto | ON | L8J 3P9 | (905) 342-9983 | 31 | DEC | 2005 | M | 2016-06-09 20:25:39 | PAD2O1 | 108 |
| Bobby | Joester | [email protected] | Ruralave | Pkwy | Oakville | ON | L9C 4B9 | (905) 728-2891 | 14 | AUG | 2004 | Oth | 2016-06-09 23:39:37 | PAD3O1 | 112 |
| Jane | Miller | [email protected] | Treetop | Crcl | Lonetown | ON | L8D 3P9 | (905) 762-9103 | 14 | SEP | 1994 | F | 2016-06-10 20:59:05 | PAD2O1 | 121 |
| Denise | Stewart | [email protected] | Municipality | Hts | Township | PE | L9C 4K6 | (905) 592-9172 | 16 | OCT | 1996 | F | 2016-06-10 21:00:36 | PAD3O1 | 123 |
| Cynthia | Brown | [email protected] | Korner | Pl | Porous | PE | L7S 4H7 | (905) 592-9172 | 16 | OCT | 1996 | F | 2016-06-10 21:01:51 | PAD2O1 | 124 |
| Mark | Jones | [email protected] | Wentworth | Crct | Urapean | ON | L9C 8Y9 | (905) 728-2891 | 14 | SEP | 2003 | M | 2016-06-10 21:04:07 | PAD3O1 | 126 |
| Ernest | Hemingway | [email protected] | Writer | Sq | Hamilton | ON | L8J 3P9 | (905) 342-9983 | 16 | OCT | 2005 | M | 2016-06-10 21:05:25 | PAD2O1 | 127 |
| Mark | Twain | [email protected] | Author | Dr | West-15th | AB | L9C 4B9 | (905) 574-1712 | 14 | OCT | 2003 | M | 2016-06-10 21:06:00 | PAD3O1 | 128 |
| Jane | Austen | [email protected] | Block | Cres | Toronto | ON | L7C 4M8 | (905) 342-9983 | 11 | JAN | 2003 | F | 2016-06-10 21:06:51 | PAD3O1 | 129 |
| James | Markinham | [email protected] | Just | Ave | Nowhere | ON | L8D 3P9 | (905) 762-9103 | 17 | SEP | 1996 | M | 2016-06-10 21:11:09 | PAD2O1 | 131 |
| Simeng | Yang | [email protected] | Somewherest | Blvd | Hamilton | ON | L9C 4B9 | (905) 574-1712 | 17 | MAR | 1998 | M | 2016-06-12 22:34:15 | PAD3O1 | 138 |
+------------+-----------+---------------------+--------------+-------------+-----------+----------+-------------+----------------+---------+-----------+----------+--------+---------------------+---------------+------------+
12 rows in set (0.00 sec)
mysql>
mysql> select * from world.classes;
+-----------+----------+
| name | class_id |
+-----------+----------+
| English | 1 |
| Calculus | 7 |
| Biology | 9 |
| Chemistry | 10 |
| Physics | 11 |
| History | 12 |
| Art | 13 |
| Gym | 14 |
+-----------+----------+
8 rows in set (0.01 sec)
mysql>
查看sleep的进程
mysql> show full processlist;
mysql> show processlist;
mysql> show processlist;
+----+-----------------+-----------------+-------+---------+------+-----------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-----------------+-----------------+-------+---------+------+-----------------------------+------------------+
| 4 | event_scheduler | localhost | NULL | Daemon | 290 | Waiting for next activation | NULL |
| 44 | root | localhost:64750 | world | Sleep | 558 | | NULL |
| 45 | root | localhost:64751 | world | Sleep | 558 | | NULL |
| 53 | root | localhost:64967 | world | Query | 0 | starting | show processlist |
+----+-----------------+-----------------+-------+---------+------+-----------------------------+------------------+
4 rows in set (0.00 sec)
查询INNODB_TRX表,就没有阻塞的事务sleep线程存在了,如下所示:
mysql> SELECT * FROM information_schema.INNODB_TRX\G;
Empty set (0.00 sec)
我们就会发现,现在可以正常执行 sql 语句了
mysql> select * from world.user_login where pid =2 and login_time > "2016-11-11 11:11:11";
+-----+---------------------+
| pid | login_time |
+-----+---------------------+
| 2 | 2016-11-25 13:30:45 |
| 2 | 2016-11-24 13:30:45 |
| 2 | 2016-11-23 10:30:45 |
| 2 | 2016-11-22 09:30:45 |
| 2 | 2016-11-21 09:30:45 |
| 2 | 2016-11-20 09:30:45 |
| 2 | 2016-11-19 09:30:45 |
+-----+---------------------+
7 rows in set (0.01 sec)
mysql> select * from world.user_login where pid =2 and login_time < "2016-11-11 11:11:11";
+-----+---------------------+
| pid | login_time |
+-----+---------------------+
| 2 | 2016-11-02 09:30:45 |
| 2 | 2016-11-01 09:30:45 |
| 2 | 2016-10-31 09:30:45 |
| 2 | 2016-10-30 09:30:45 |
| 2 | 2016-10-29 09:30:45 |
+-----+---------------------+
5 rows in set (0.00 sec)
mysql> select * from world.user_login where pid =2 and login_time = "2016-11-11 11:11:11";
Empty set (0.00 sec)
mysql>
mysql> select * from world.user_login where pid =2 and login_time < "2016-10-29 11:11:11";
+-----+---------------------+
| pid | login_time |
+-----+---------------------+
| 2 | 2016-10-29 09:30:45 |
+-----+---------------------+
1 row in set (0.00 sec)
mysql>