1connect  master,127.0.0.1,root,,test,$MASTER_MYPORT,;
2connect  slave,127.0.0.1,root,,test,$SLAVE_MYPORT,;
3connection master;
4CREATE DATABASE federated;
5connection slave;
6CREATE DATABASE federated;
7connection slave;
8create database first_db;
9create database second_db;
10use first_db;
11DROP TABLE IF EXISTS first_db.t1;
12Warnings:
13Note	1051	Unknown table 'first_db.t1'
14CREATE TABLE first_db.t1 (
15`id` int(20) NOT NULL,
16`name` varchar(64) NOT NULL default ''
17    )
18DEFAULT CHARSET=latin1;
19DROP TABLE IF EXISTS first_db.t2;
20Warnings:
21Note	1051	Unknown table 'first_db.t2'
22CREATE TABLE first_db.t2 (
23`id` int(20) NOT NULL,
24`name` varchar(64) NOT NULL default ''
25    )
26DEFAULT CHARSET=latin1;
27use second_db;
28DROP TABLE IF EXISTS second_db.t1;
29Warnings:
30Note	1051	Unknown table 'second_db.t1'
31CREATE TABLE second_db.t1 (
32`id` int(20) NOT NULL,
33`name` varchar(64) NOT NULL default ''
34    )
35DEFAULT CHARSET=latin1;
36DROP TABLE IF EXISTS second_db.t2;
37Warnings:
38Note	1051	Unknown table 'second_db.t2'
39CREATE TABLE second_db.t2 (
40`id` int(20) NOT NULL,
41`name` varchar(64) NOT NULL default ''
42    )
43DEFAULT CHARSET=latin1;
44connection master;
45drop server if exists 'server_one';
46create server 'server_one' foreign data wrapper 'mysql' options
47(HOST '127.0.0.1',
48DATABASE 'first_db',
49USER 'root',
50PASSWORD '',
51PORT SLAVE_PORT,
52SOCKET '',
53OWNER 'root');
54drop server if exists 'server_two';
55create server 'server_two' foreign data wrapper 'mysql' options
56(HOST '127.0.0.1',
57DATABASE 'second_db',
58USER 'root',
59PASSWORD '',
60PORT SLAVE_PORT,
61SOCKET '',
62OWNER 'root');
63select * from mysql.servers order by db;
64Server_name	Host	Db	Username	Password	Port	Socket	Wrapper	Owner
65server_one	127.0.0.1	first_db	root		SLAVE_PORT		mysql	root
66server_two	127.0.0.1	second_db	root		SLAVE_PORT		mysql	root
67DROP TABLE IF EXISTS federated.old;
68Warnings:
69Note	1051	Unknown table 'federated.old'
70CREATE TABLE federated.old (
71`id` int(20) NOT NULL,
72`name` varchar(64) NOT NULL default ''
73    )
74ENGINE="FEDERATED" DEFAULT CHARSET=latin1
75CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/first_db/t1';
76INSERT INTO federated.old (id, name) values (1, 'federated.old-> first_db.t1, url format');
77SELECT * FROM federated.old;
78id	name
791	federated.old-> first_db.t1, url format
80DROP TABLE IF EXISTS federated.old2;
81Warnings:
82Note	1051	Unknown table 'federated.old2'
83CREATE TABLE federated.old2 (
84`id` int(20) NOT NULL,
85`name` varchar(64) NOT NULL default ''
86    )
87ENGINE="FEDERATED" DEFAULT CHARSET=latin1
88CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/first_db/t2';
89INSERT INTO federated.old2 (id, name) values (1, 'federated.old2-> first_db.t2, url format');
90SELECT * FROM federated.old2;
91id	name
921	federated.old2-> first_db.t2, url format
93DROP TABLE IF EXISTS federated.urldb2t1;
94Warnings:
95Note	1051	Unknown table 'federated.urldb2t1'
96CREATE TABLE federated.urldb2t1 (
97`id` int(20) NOT NULL,
98`name` varchar(64) NOT NULL default ''
99    )
100ENGINE="FEDERATED" DEFAULT CHARSET=latin1
101CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/second_db/t1';
102INSERT INTO federated.urldb2t1 (id, name) values (1, 'federated.urldb2t1 -> second_db.t1, url format');
103SELECT * FROM federated.urldb2t1;
104id	name
1051	federated.urldb2t1 -> second_db.t1, url format
106DROP TABLE IF EXISTS federated.urldb2t2;
107Warnings:
108Note	1051	Unknown table 'federated.urldb2t2'
109CREATE TABLE federated.urldb2t2 (
110`id` int(20) NOT NULL,
111`name` varchar(64) NOT NULL default ''
112    )
113ENGINE="FEDERATED" DEFAULT CHARSET=latin1
114CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/second_db/t2';
115INSERT INTO federated.urldb2t2 (id, name) values (1, 'federated.urldb2t2 -> second_db.t2, url format');
116SELECT * FROM federated.urldb2t2;
117id	name
1181	federated.urldb2t2 -> second_db.t2, url format
119DROP TABLE IF EXISTS federated.t1;
120Warnings:
121Note	1051	Unknown table 'federated.t1'
122CREATE TABLE federated.t1 (
123`id` int(20) NOT NULL,
124`name` varchar(64) NOT NULL default ''
125    )
126ENGINE="FEDERATED" DEFAULT CHARSET=latin1
127CONNECTION='server_one';
128INSERT INTO federated.t1 (id, name) values (1, 'server_one, new scheme, first_db.t1');
129SELECT * FROM federated.t1;
130id	name
1311	federated.old-> first_db.t1, url format
1321	server_one, new scheme, first_db.t1
133DROP TABLE IF EXISTS federated.whatever;
134Warnings:
135Note	1051	Unknown table 'federated.whatever'
136CREATE TABLE federated.whatever (
137`id` int(20) NOT NULL,
138`name` varchar(64) NOT NULL default ''
139    )
140ENGINE="FEDERATED" DEFAULT CHARSET=latin1
141CONNECTION='server_one/t1';
142INSERT INTO federated.whatever (id, name) values (1, 'server_one, new scheme, whatever, first_db.t1');
143SELECT * FROM federated.whatever;
144id	name
1451	federated.old-> first_db.t1, url format
1461	server_one, new scheme, first_db.t1
1471	server_one, new scheme, whatever, first_db.t1
148ALTER SERVER 'server_one' options(DATABASE 'second_db');
149INSERT INTO federated.t1 (id, name) values (1, 'server_two, new scheme, second_db.t1');
150SELECT * FROM federated.t1;
151id	name
1521	federated.urldb2t1 -> second_db.t1, url format
1531	server_two, new scheme, second_db.t1
154INSERT INTO federated.whatever (id, name) values (1, 'server_two, new scheme, whatever, second_db.t1');
155SELECT * FROM federated.whatever;
156id	name
1571	federated.urldb2t1 -> second_db.t1, url format
1581	server_two, new scheme, second_db.t1
1591	server_two, new scheme, whatever, second_db.t1
160drop table federated.t1;
161drop server 'server_one';
162drop server 'server_two';
163select * from mysql.servers order by db;
164Server_name	Host	Db	Username	Password	Port	Socket	Wrapper	Owner
165connection slave;
166drop table first_db.t1;
167drop table second_db.t1;
168drop database first_db;
169drop database second_db;
170create database db_legitimate;
171create database db_bogus;
172use db_legitimate;
173CREATE TABLE db_legitimate.t1 (
174`id` int(20) NOT NULL,
175`name` varchar(64) NOT NULL default ''
176    );
177INSERT INTO db_legitimate.t1 VALUES ('1','this is legitimate');
178use db_bogus;
179CREATE TABLE db_bogus.t1 (
180`id` int(20) NOT NULL,
181`name` varchar(64) NOT NULL default ''
182    )
183;
184INSERT INTO db_bogus.t1 VALUES ('2','this is bogus');
185connection slave;
186create user test_fed@localhost identified by 'foo';
187grant all on db_legitimate.* to test_fed@localhost;
188connection master;
189create server 's1' foreign data wrapper 'mysql' options
190(HOST '127.0.0.1',
191DATABASE 'db_legitimate',
192USER 'test_fed',
193PASSWORD 'foo',
194PORT SLAVE_PORT,
195SOCKET '',
196OWNER 'root');
197create user guest_select@localhost;
198grant select on federated.* to guest_select@localhost;
199create user guest_super@localhost;
200grant select,SUPER,RELOAD on *.* to guest_super@localhost;
201create user guest_usage@localhost;
202grant usage on *.* to guest_usage@localhost;
203CREATE TABLE federated.t1 (
204`id` int(20) NOT NULL,
205`name` varchar(64) NOT NULL default ''
206    ) ENGINE = FEDERATED CONNECTION = 's1';
207select * from federated.t1;
208id	name
2091	this is legitimate
210connect  conn_select,127.0.0.1,guest_select,,federated,$MASTER_MYPORT;
211connect  conn_usage,127.0.0.1,guest_usage,,,$MASTER_MYPORT;
212connect  conn_super,127.0.0.1,guest_super,,,$MASTER_MYPORT;
213connection conn_select;
214alter server s1 options (database 'db_bogus');
215ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
216connection master;
217flush tables;
218select * from federated.t1;
219id	name
2201	this is legitimate
221connection conn_usage;
222alter server s1 options (database 'db_bogus');
223ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
224connection master;
225flush tables;
226select * from federated.t1;
227id	name
2281	this is legitimate
229connection conn_super;
230alter server s1 options (database 'db_bogus');
231connection master;
232flush tables;
233select * from federated.t1;
234Got one of the listed errors
235connection conn_select;
236drop server if exists 's1';
237ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
238create server 's1' foreign data wrapper 'mysql' options
239(HOST '127.0.0.1',
240DATABASE 'db_legitimate',
241USER 'test_fed',
242PASSWORD 'foo',
243PORT SLAVE_PORT,
244SOCKET '',
245OWNER 'root');
246ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
247connection conn_super;
248drop server 's1';
249create server 's1' foreign data wrapper 'mysql' options
250(HOST '127.0.0.1',
251DATABASE 'db_legitimate',
252USER 'test_fed',
253PASSWORD 'foo',
254PORT SLAVE_PORT,
255SOCKET '',
256OWNER 'root');
257connection master;
258flush tables;
259select * from federated.t1;
260id	name
2611	this is legitimate
262connection slave;
263drop user test_fed@localhost;
264drop database db_legitimate;
265drop database db_bogus;
266disconnect conn_select;
267disconnect conn_usage;
268disconnect conn_super;
269connection master;
270drop user guest_super@localhost;
271drop user guest_usage@localhost;
272drop user guest_select@localhost;
273drop table federated.t1;
274drop server 's1';
275create server 's1' foreign data wrapper 'mysql' options (host 'foo');
276alter server 's1' options
277(host 'localhost', database '', user '',
278password '', socket '', owner '', port 3306);
279alter server 's1' options
280(host 'localhost', database 'database1', user '',
281password '', socket '', owner '', port 3306);
282drop server 's1';
283# End of 5.1 tests
284connect  other,localhost,root,,;
285connection master;
286use test;
287create table t1(a int);
288insert into t1 values (1);
289create procedure p1 ()
290begin
291DECLARE v INT DEFAULT 0;
292DECLARE i INT;
293DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END;
294SET i = sleep(5);
295WHILE v < 10000 do
296CREATE SERVER s
297FOREIGN DATA WRAPPER mysql
298OPTIONS (USER 'Remote', HOST '192.168.1.106', DATABASE 'test');
299ALTER SERVER s OPTIONS (USER 'Remote');
300DROP SERVER s;
301SET v = v + 1;
302END WHILE;
303select a into @a from t1; # Just reset warnings
304END//
305connection other;
306use test;
307call p1();
308connection master;
309call p1();
310connection other;
311drop procedure p1;
312drop table t1;
313drop server if exists s;
314connection master;
315DROP TABLE IF EXISTS federated.t1;
316DROP DATABASE IF EXISTS federated;
317connection slave;
318DROP TABLE IF EXISTS federated.t1;
319DROP DATABASE IF EXISTS federated;
320