1
SHOW TABLES FROM information_schema LIKE 'TABLES';
2
Tables_in_information_schema (TABLES)
4
#######################################################################
5
# Testcase 3.2.1.1: INFORMATION_SCHEMA tables can be queried via SELECT
6
#######################################################################
7
DROP VIEW IF EXISTS test.v1;
8
DROP PROCEDURE IF EXISTS test.p1;
9
DROP FUNCTION IF EXISTS test.f1;
10
CREATE VIEW test.v1 AS SELECT * FROM information_schema.TABLES;
11
CREATE PROCEDURE test.p1() SELECT * FROM information_schema.TABLES;
12
CREATE FUNCTION test.f1() returns BIGINT
14
DECLARE counter BIGINT DEFAULT NULL;
15
SELECT COUNT(*) INTO counter FROM information_schema.TABLES;
18
# Attention: The printing of the next result sets is disabled.
19
SELECT * FROM information_schema.TABLES;
20
SELECT * FROM test.v1;
24
DROP PROCEDURE test.p1;
25
DROP FUNCTION test.f1;
26
#########################################################################
27
# Testcase 3.2.12.1: INFORMATION_SCHEMA.TABLES layout
28
#########################################################################
29
DESCRIBE information_schema.TABLES;
30
Field Type Null Key Default Extra
31
TABLE_CATALOG varchar(512) YES NULL
32
TABLE_SCHEMA varchar(64) NO
33
TABLE_NAME varchar(64) NO
34
TABLE_TYPE varchar(64) NO
35
ENGINE varchar(64) YES NULL
36
VERSION bigint(21) unsigned YES NULL
37
ROW_FORMAT varchar(10) YES NULL
38
TABLE_ROWS bigint(21) unsigned YES NULL
39
AVG_ROW_LENGTH bigint(21) unsigned YES NULL
40
DATA_LENGTH bigint(21) unsigned YES NULL
41
MAX_DATA_LENGTH bigint(21) unsigned YES NULL
42
INDEX_LENGTH bigint(21) unsigned YES NULL
43
DATA_FREE bigint(21) unsigned YES NULL
44
AUTO_INCREMENT bigint(21) unsigned YES NULL
45
CREATE_TIME datetime YES NULL
46
UPDATE_TIME datetime YES NULL
47
CHECK_TIME datetime YES NULL
48
TABLE_COLLATION varchar(64) YES NULL
49
CHECKSUM bigint(21) unsigned YES NULL
50
CREATE_OPTIONS varchar(255) YES NULL
51
TABLE_COMMENT varchar(2048) NO
52
SHOW CREATE TABLE information_schema.TABLES;
54
TABLES CREATE TEMPORARY TABLE `TABLES` (
55
`TABLE_CATALOG` varchar(512) DEFAULT NULL,
56
`TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT '',
57
`TABLE_NAME` varchar(64) NOT NULL DEFAULT '',
58
`TABLE_TYPE` varchar(64) NOT NULL DEFAULT '',
59
`ENGINE` varchar(64) DEFAULT NULL,
60
`VERSION` bigint(21) unsigned DEFAULT NULL,
61
`ROW_FORMAT` varchar(10) DEFAULT NULL,
62
`TABLE_ROWS` bigint(21) unsigned DEFAULT NULL,
63
`AVG_ROW_LENGTH` bigint(21) unsigned DEFAULT NULL,
64
`DATA_LENGTH` bigint(21) unsigned DEFAULT NULL,
65
`MAX_DATA_LENGTH` bigint(21) unsigned DEFAULT NULL,
66
`INDEX_LENGTH` bigint(21) unsigned DEFAULT NULL,
67
`DATA_FREE` bigint(21) unsigned DEFAULT NULL,
68
`AUTO_INCREMENT` bigint(21) unsigned DEFAULT NULL,
69
`CREATE_TIME` datetime DEFAULT NULL,
70
`UPDATE_TIME` datetime DEFAULT NULL,
71
`CHECK_TIME` datetime DEFAULT NULL,
72
`TABLE_COLLATION` varchar(64) DEFAULT NULL,
73
`CHECKSUM` bigint(21) unsigned DEFAULT NULL,
74
`CREATE_OPTIONS` varchar(255) DEFAULT NULL,
75
`TABLE_COMMENT` varchar(2048) NOT NULL DEFAULT ''
76
) ENGINE=MEMORY DEFAULT CHARSET=utf8
77
SHOW COLUMNS FROM information_schema.TABLES;
78
Field Type Null Key Default Extra
79
TABLE_CATALOG varchar(512) YES NULL
80
TABLE_SCHEMA varchar(64) NO
81
TABLE_NAME varchar(64) NO
82
TABLE_TYPE varchar(64) NO
83
ENGINE varchar(64) YES NULL
84
VERSION bigint(21) unsigned YES NULL
85
ROW_FORMAT varchar(10) YES NULL
86
TABLE_ROWS bigint(21) unsigned YES NULL
87
AVG_ROW_LENGTH bigint(21) unsigned YES NULL
88
DATA_LENGTH bigint(21) unsigned YES NULL
89
MAX_DATA_LENGTH bigint(21) unsigned YES NULL
90
INDEX_LENGTH bigint(21) unsigned YES NULL
91
DATA_FREE bigint(21) unsigned YES NULL
92
AUTO_INCREMENT bigint(21) unsigned YES NULL
93
CREATE_TIME datetime YES NULL
94
UPDATE_TIME datetime YES NULL
95
CHECK_TIME datetime YES NULL
96
TABLE_COLLATION varchar(64) YES NULL
97
CHECKSUM bigint(21) unsigned YES NULL
98
CREATE_OPTIONS varchar(255) YES NULL
99
TABLE_COMMENT varchar(2048) NO
100
SELECT table_catalog, table_schema, table_name
101
FROM information_schema.tables WHERE table_catalog IS NOT NULL;
102
table_catalog table_schema table_name
103
################################################################################
104
# Testcase 3.2.12.2 + 3.2.12.3: INFORMATION_SCHEMA.TABLES accessible information
105
################################################################################
106
DROP DATABASE IF EXISTS db_datadict;
107
CREATE DATABASE db_datadict;
108
DROP USER 'testuser1'@'localhost';
109
CREATE USER 'testuser1'@'localhost';
110
GRANT CREATE, CREATE VIEW, INSERT, SELECT ON db_datadict.*
111
TO 'testuser1'@'localhost' WITH GRANT OPTION;
112
DROP USER 'testuser2'@'localhost';
113
CREATE USER 'testuser2'@'localhost';
114
DROP USER 'testuser3'@'localhost';
115
CREATE USER 'testuser3'@'localhost';
116
CREATE TABLE db_datadict.tb1 (f1 INT, f2 INT, f3 INT)
117
ENGINE = <engine_type>;
118
GRANT SELECT ON db_datadict.tb1 TO 'testuser1'@'localhost';
119
GRANT ALL ON db_datadict.tb1 TO 'testuser2'@'localhost' WITH GRANT OPTION;
120
# Establish connection testuser1 (user=testuser1)
121
CREATE TABLE tb2 (f1 DECIMAL)
122
ENGINE = <engine_type>;
123
CREATE TABLE tb3 (f1 VARCHAR(200))
124
ENGINE = <engine_type>;
125
GRANT SELECT ON db_datadict.tb3 to 'testuser3'@'localhost';
126
GRANT INSERT ON db_datadict.tb3 to 'testuser2'@'localhost';
127
CREATE VIEW v3 AS SELECT * FROM tb3;
128
GRANT SELECT ON db_datadict.v3 to 'testuser3'@'localhost';
129
SELECT * FROM information_schema.tables
130
WHERE table_schema = 'db_datadict' ORDER BY table_name;
131
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT
132
NULL db_datadict tb1 BASE TABLE #ENG# 10 #RF# 0 #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# latin1_swedish_ci #CS#
133
NULL db_datadict tb2 BASE TABLE #ENG# 10 #RF# 0 #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# latin1_swedish_ci #CS#
134
NULL db_datadict tb3 BASE TABLE #ENG# 10 #RF# 0 #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# latin1_swedish_ci #CS#
135
NULL db_datadict v3 VIEW #ENG# NULL #RF# NULL #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# NULL #CS# NULL VIEW
136
SHOW TABLES FROM db_datadict;
137
Tables_in_db_datadict
142
# Establish connection testuser2 (user=testuser2)
143
SELECT * FROM information_schema.tables
144
WHERE table_schema = 'db_datadict' ORDER BY table_name;
145
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT
146
NULL db_datadict tb1 BASE TABLE #ENG# 10 #RF# 0 #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# latin1_swedish_ci #CS#
147
NULL db_datadict tb3 BASE TABLE #ENG# 10 #RF# 0 #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# latin1_swedish_ci #CS#
148
SHOW TABLES FROM db_datadict;
149
Tables_in_db_datadict
152
# Establish connection testuser3 (user=testuser3)
153
SELECT * FROM information_schema.tables
154
WHERE table_schema = 'db_datadict' ORDER BY table_name;
155
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT
156
NULL db_datadict tb3 BASE TABLE #ENG# 10 #RF# 0 #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# latin1_swedish_ci #CS#
157
NULL db_datadict v3 VIEW #ENG# NULL #RF# NULL #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# NULL #CS# NULL VIEW
158
SHOW TABLES FROM db_datadict;
159
Tables_in_db_datadict
162
# Switch to connection default (user=root)
163
SELECT * FROM information_schema.tables
164
WHERE table_schema = 'db_datadict' ORDER BY table_name;
165
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT
166
NULL db_datadict tb1 BASE TABLE #ENG# 10 #RF# 0 #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# latin1_swedish_ci #CS#
167
NULL db_datadict tb2 BASE TABLE #ENG# 10 #RF# 0 #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# latin1_swedish_ci #CS#
168
NULL db_datadict tb3 BASE TABLE #ENG# 10 #RF# 0 #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# latin1_swedish_ci #CS#
169
NULL db_datadict v3 VIEW #ENG# NULL #RF# NULL #ARL# #DL# #MDL# #IL# #DF# NULL #CRT #UT# #CT# NULL #CS# NULL VIEW
170
SHOW TABLES FROM db_datadict;
171
Tables_in_db_datadict
176
# Close connection testuser1, testuser2, testuser3
177
DROP USER 'testuser1'@'localhost';
178
DROP USER 'testuser2'@'localhost';
179
DROP USER 'testuser3'@'localhost';
180
DROP DATABASE db_datadict;
181
#########################################################################
182
# 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.TABLES modifications
183
#########################################################################
184
DROP TABLE IF EXISTS test.t1_my_table;
185
DROP DATABASE IF EXISTS db_datadict;
186
CREATE DATABASE db_datadict;
187
SELECT table_name FROM information_schema.tables
188
WHERE table_name LIKE 't1_my_table%';
190
CREATE TABLE test.t1_my_table (f1 BIGINT)
191
DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci
192
COMMENT = 'Initial Comment' ENGINE = <engine_type>;
193
SELECT * FROM information_schema.tables
194
WHERE table_name = 't1_my_table';
197
TABLE_NAME t1_my_table
198
TABLE_TYPE BASE TABLE
205
MAX_DATA_LENGTH #MDL#
212
TABLE_COLLATION latin1_swedish_ci
215
TABLE_COMMENT Initial Comment
216
SELECT table_name FROM information_schema.tables
217
WHERE table_name LIKE 't1_my_table%';
220
RENAME TABLE test.t1_my_table TO test.t1_my_tablex;
221
SELECT table_name FROM information_schema.tables
222
WHERE table_name LIKE 't1_my_table%';
225
SELECT table_schema,table_name FROM information_schema.tables
226
WHERE table_name = 't1_my_tablex';
227
table_schema table_name
229
RENAME TABLE test.t1_my_tablex TO db_datadict.t1_my_tablex;
230
SELECT table_schema,table_name FROM information_schema.tables
231
WHERE table_name = 't1_my_tablex';
232
table_schema table_name
233
db_datadict t1_my_tablex
234
SELECT table_name, engine FROM information_schema.tables
235
WHERE table_name = 't1_my_tablex';
237
t1_my_tablex <engine_type>
238
ALTER TABLE db_datadict.t1_my_tablex
239
ENGINE = <other_engine_type>;
240
SELECT table_name, engine FROM information_schema.tables
241
WHERE table_name = 't1_my_tablex';
243
t1_my_tablex <other_engine_type>
244
SELECT table_name, table_rows FROM information_schema.tables
245
WHERE table_name = 't1_my_tablex';
246
table_name table_rows
248
INSERT INTO db_datadict.t1_my_tablex VALUES(1),(2);
249
SELECT table_name, table_rows FROM information_schema.tables
250
WHERE table_name = 't1_my_tablex';
251
table_name table_rows
253
SELECT table_name, table_collation FROM information_schema.tables
254
WHERE table_name = 't1_my_tablex';
255
table_name table_collation
256
t1_my_tablex latin1_swedish_ci
257
ALTER TABLE db_datadict.t1_my_tablex DEFAULT CHARACTER SET utf8;
258
SELECT table_name, table_collation FROM information_schema.tables
259
WHERE table_name = 't1_my_tablex';
260
table_name table_collation
261
t1_my_tablex utf8_general_ci
262
SELECT table_name, table_collation FROM information_schema.tables
263
WHERE table_name = 't1_my_tablex';
264
table_name table_collation
265
t1_my_tablex utf8_general_ci
266
ALTER TABLE db_datadict.t1_my_tablex
267
DEFAULT CHARACTER SET latin1 COLLATE latin1_german1_ci;
268
SELECT table_name, table_collation FROM information_schema.tables
269
WHERE table_name = 't1_my_tablex';
270
table_name table_collation
271
t1_my_tablex latin1_german1_ci
272
SELECT table_name, TABLE_COMMENT FROM information_schema.tables
273
WHERE table_name = 't1_my_tablex';
274
table_name TABLE_COMMENT
275
t1_my_tablex Initial Comment
276
ALTER TABLE db_datadict.t1_my_tablex COMMENT 'Changed Comment';
277
SELECT table_name, TABLE_COMMENT FROM information_schema.tables
278
WHERE table_name = 't1_my_tablex';
279
table_name TABLE_COMMENT
280
t1_my_tablex Changed Comment
281
SELECT table_name, AUTO_INCREMENT FROM information_schema.tables
282
WHERE table_name = 't1_my_tablex';
283
table_name AUTO_INCREMENT
285
ALTER TABLE db_datadict.t1_my_tablex
286
ADD f2 BIGINT AUTO_INCREMENT, ADD PRIMARY KEY (f2);
287
SELECT table_name, AUTO_INCREMENT FROM information_schema.tables
288
WHERE table_name = 't1_my_tablex';
289
table_name AUTO_INCREMENT
291
SELECT table_name, ROW_FORMAT FROM information_schema.tables
292
WHERE table_name = 't1_my_tablex';
293
table_name ROW_FORMAT
295
ALTER TABLE db_datadict.t1_my_tablex ROW_FORMAT = dynamic;
296
SELECT table_name, ROW_FORMAT FROM information_schema.tables
297
WHERE table_name = 't1_my_tablex';
298
table_name ROW_FORMAT
300
SELECT table_name, checksum FROM information_schema.tables
301
WHERE table_name = 't1_my_tablex';
304
ALTER TABLE db_datadict.t1_my_tablex CHECKSUM = 1;
305
SELECT table_name, checksum IS NOT NULL FROM information_schema.tables
306
WHERE table_name = 't1_my_tablex';
307
table_name checksum IS NOT NULL
309
SELECT UPDATE_TIME, checksum INTO @UPDATE_TIME, @checksum
310
FROM information_schema.tables
311
WHERE table_name = 't1_my_tablex';
312
INSERT INTO db_datadict.t1_my_tablex SET f1 = 3;
313
SELECT UPDATE_TIME > @UPDATE_TIME
314
AS "Is current UPDATE_TIME bigger than before last INSERT?"
315
FROM information_schema.tables
316
WHERE table_name = 't1_my_tablex';
317
Is current UPDATE_TIME bigger than before last INSERT?
319
SELECT checksum <> @checksum
320
AS "Is current CHECKSUM different than before last INSERT?"
321
FROM information_schema.tables
322
WHERE table_name = 't1_my_tablex';
323
Is current CHECKSUM different than before last INSERT?
325
SELECT CREATE_TIME INTO @CREATE_TIME FROM information_schema.tables
326
WHERE table_name = 't1_my_tablex';
327
SELECT table_name FROM information_schema.tables
328
WHERE table_name LIKE 't1_my_table%';
331
DROP TABLE db_datadict.t1_my_tablex;
332
SELECT table_name FROM information_schema.tables
333
WHERE table_name LIKE 't1_my_table%';
335
CREATE TABLE test.t1_my_tablex (f1 BIGINT)
336
ENGINE = <other_engine_type>;
337
SELECT CREATE_TIME > @CREATE_TIME
338
AS "Is current CREATE_TIME bigger than for the old dropped table?"
339
FROM information_schema.tables
340
WHERE table_name = 't1_my_tablex';
341
Is current CREATE_TIME bigger than for the old dropped table?
343
DROP TABLE test.t1_my_tablex;
344
CREATE VIEW test.t1_my_tablex AS SELECT 1;
345
SELECT * FROM information_schema.tables
346
WHERE table_name = 't1_my_tablex';
349
TABLE_NAME t1_my_tablex
368
DROP VIEW test.t1_my_tablex;
369
SELECT table_name FROM information_schema.tables
370
WHERE table_name = 't1_my_tablex';
372
CREATE TEMPORARY TABLE test.t1_my_tablex
373
ENGINE = <other_engine_type>
375
SELECT table_name, table_type FROM information_schema.tables
376
WHERE table_name = 't1_my_tablex';
377
DROP TEMPORARY TABLE test.t1_my_tablex;
378
CREATE TABLE db_datadict.t1_my_tablex
379
ENGINE = <engine_type> AS
381
SELECT table_name FROM information_schema.tables
382
WHERE table_name = 't1_my_tablex';
385
DROP DATABASE db_datadict;
386
SELECT table_name FROM information_schema.tables
387
WHERE table_name = 't1_my_tablex';
389
########################################################################
390
# Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
391
# DDL on INFORMATION_SCHEMA tables are not supported
392
########################################################################
393
DROP DATABASE IF EXISTS db_datadict;
394
CREATE DATABASE db_datadict;
395
CREATE TABLE db_datadict.t1 (f1 BIGINT)
396
ENGINE = <engine_type>;
397
INSERT INTO information_schema.tables
398
SELECT * FROM information_schema.tables;
399
ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
400
UPDATE information_schema.tables SET table_schema = 'test'
401
WHERE table_name = 't1';
402
ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
403
DELETE FROM information_schema.tables WHERE table_name = 't1';
404
ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
405
TRUNCATE information_schema.tables;
406
ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
407
CREATE INDEX my_idx_on_tables ON information_schema.tables(table_schema);
408
ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
409
ALTER TABLE information_schema.tables DROP PRIMARY KEY;
410
ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
411
ALTER TABLE information_schema.tables ADD f1 INT;
412
ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
413
DROP TABLE information_schema.tables;
414
ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
415
ALTER TABLE information_schema.tables RENAME db_datadict.tables;
416
ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
417
ALTER TABLE information_schema.tables RENAME information_schema.xtables;
418
ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
419
DROP DATABASE db_datadict;