Skip to content

Commit c550a45

Browse files
author
msvensson@pilot.blaudden
committed
Bug#20166 mysql-test-run.pl does not test system privilege tables creation
- Use mysql_system_tables.sql to create MySQL system tables in all places where we create them(mysql_install_db, mysql-test-run-pl and mysql_fix_privilege_tables.sql)
1 parent 6caa0a2 commit c550a45

31 files changed

+354
-1793
lines changed

.bzrignore

+1
Original file line numberDiff line numberDiff line change
@@ -1335,3 +1335,4 @@ win/vs71cache.txt
13351335
win/vs8cache.txt
13361336
zlib/*.ds?
13371337
zlib/*.vcproj
1338+
scripts/mysql_fix_privilege_tables.sql

mysql-test/Makefile.am

-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ dist-hook:
6666
$(INSTALL_DATA) $(srcdir)/std_data/*.frm $(distdir)/std_data
6767
$(INSTALL_DATA) $(srcdir)/std_data/*.MY* $(distdir)/std_data
6868
$(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(distdir)/std_data
69-
$(INSTALL_DATA) $(srcdir)/lib/init_db.sql $(distdir)/lib
7069
$(INSTALL_DATA) $(srcdir)/lib/*.pl $(distdir)/lib
7170

7271
install-data-local:
@@ -98,7 +97,6 @@ install-data-local:
9897
$(INSTALL_DATA) $(srcdir)/std_data/*.frm $(DESTDIR)$(testdir)/std_data
9998
$(INSTALL_DATA) $(srcdir)/std_data/*.MY* $(DESTDIR)$(testdir)/std_data
10099
$(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(DESTDIR)$(testdir)/std_data
101-
$(INSTALL_DATA) $(srcdir)/lib/init_db.sql $(DESTDIR)$(testdir)/lib
102100
$(INSTALL_DATA) $(srcdir)/lib/*.pl $(DESTDIR)$(testdir)/lib
103101

104102
uninstall-local:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Allow anonymous users to connect
2+
disable_warnings;
3+
disable_query_log;
4+
INSERT INTO mysql.user (host, user) VALUES ('localhost','');
5+
FLUSH PRIVILEGES;
6+
enable_query_log;
7+
enable_warnings;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Remove anonymous users added by add_anonymous_users.inc
2+
disable_query_log;
3+
DELETE FROM mysql.user where host='localhost' and user='';
4+
FLUSH PRIVILEGES;
5+
enable_query_log;

mysql-test/init_db.sql

-58
This file was deleted.

mysql-test/lib/init_db.sql

-559
This file was deleted.

mysql-test/mysql-test-run.pl

+37-34
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@
299299
our $exe_ndb_example;
300300
our $path_ndb_testrun_log;
301301

302+
our $path_sql_dir;
303+
302304
our @data_dir_lst;
303305

304306
our $used_binlog_format;
@@ -1497,12 +1499,16 @@ ()
14971499
$exe_mysql_fix_system_tables=
14981500
mtr_script_exists("$glob_basedir/scripts/mysql_fix_privilege_tables",
14991501
"$path_client_bindir/mysql_fix_privilege_tables");
1502+
15001503
}
15011504

1505+
# Look for SQL scripts directory
1506+
$path_sql_dir= mtr_path_exists("$glob_basedir/share",
1507+
"$glob_basedir/scripts");
1508+
15021509
# Look for mysql_fix_privilege_tables.sql script
15031510
$file_mysql_fix_privilege_tables=
1504-
mtr_file_exists("$glob_basedir/scripts/mysql_fix_privilege_tables.sql",
1505-
"$glob_basedir/share/mysql_fix_privilege_tables.sql");
1511+
mtr_file_exists("$path_sql_dir/mysql_fix_privilege_tables.sql");
15061512

15071513
if ( ! $opt_skip_ndbcluster and executable_setup_ndb())
15081514
{
@@ -1940,6 +1946,7 @@ ()
19401946
"--port=$master->[0]->{'port'} " .
19411947
"--socket=$master->[0]->{'path_sock'}";
19421948
$ENV{'MYSQL_FIX_SYSTEM_TABLES'}= $cmdline_mysql_fix_system_tables;
1949+
19431950
}
19441951
$ENV{'MYSQL_FIX_PRIVILEGE_TABLES'}= $file_mysql_fix_privilege_tables;
19451952

@@ -2856,38 +2863,11 @@ ($$)
28562863
my $type= shift;
28572864
my $data_dir= shift;
28582865

2859-
my $init_db_sql= "lib/init_db.sql";
2860-
my $init_db_sql_tmp= "/tmp/init_db.sql$$";
2861-
my $args;
2862-
28632866
mtr_report("Installing \u$type Database");
28642867

2865-
open(IN, $init_db_sql)
2866-
or mtr_error("Can't open $init_db_sql: $!");
2867-
open(OUT, ">", $init_db_sql_tmp)
2868-
or mtr_error("Can't write to $init_db_sql_tmp: $!");
2869-
while (<IN>)
2870-
{
2871-
chomp;
2872-
s/\@HOSTNAME\@/$glob_hostname/;
2873-
if ( /^\s*$/ )
2874-
{
2875-
print OUT "\n";
2876-
}
2877-
elsif (/;$/)
2878-
{
2879-
print OUT "$_\n";
2880-
}
2881-
else
2882-
{
2883-
print OUT "$_ ";
2884-
}
2885-
}
2886-
close OUT;
2887-
close IN;
28882868

2869+
my $args;
28892870
mtr_init_args(\$args);
2890-
28912871
mtr_add_arg($args, "--no-defaults");
28922872
mtr_add_arg($args, "--bootstrap");
28932873
mtr_add_arg($args, "--basedir=%s", $path_my_basedir);
@@ -2921,21 +2901,44 @@ ($$)
29212901
# ----------------------------------------------------------------------
29222902
$ENV{'MYSQLD_BOOTSTRAP_CMD'}= "$exe_mysqld_bootstrap " . join(" ", @$args);
29232903

2904+
# ----------------------------------------------------------------------
2905+
# Create the bootstrap.sql file
2906+
# ----------------------------------------------------------------------
2907+
my $bootstrap_sql_file= "$opt_vardir/tmp/bootstrap.sql$$";
2908+
2909+
# Use the mysql database for system tables
2910+
mtr_tofile($bootstrap_sql_file, "use mysql");
2911+
2912+
# Add the offical mysql system tables and initial system data
2913+
# for a prodcuction system
2914+
mtr_appendfile_to_file("$path_sql_dir/mysql_system_tables.sql",
2915+
$bootstrap_sql_file);
2916+
2917+
# Add test data for timezone - this is just a subset, on a real
2918+
# system these tables will be populated either by mysql_tzinfo_to_sql
2919+
# or by downloading the timezone table package from our website
2920+
mtr_appendfile_to_file("$path_sql_dir/mysql_test_data_timezone.sql",
2921+
$bootstrap_sql_file);
2922+
2923+
# Fill help tables, just an empty file when running from bk repo
2924+
# but will be replaced by a real fill_help_tables.sql when
2925+
# building the source dist
2926+
mtr_appendfile_to_file("$path_sql_dir/fill_help_tables.sql",
2927+
$bootstrap_sql_file);
2928+
29242929
# Log bootstrap command
29252930
my $path_bootstrap_log= "$opt_vardir/log/bootstrap.log";
29262931
mtr_tofile($path_bootstrap_log,
29272932
"$exe_mysqld_bootstrap " . join(" ", @$args) . "\n");
29282933

2929-
if ( mtr_run($exe_mysqld_bootstrap, $args, $init_db_sql_tmp,
2934+
if ( mtr_run($exe_mysqld_bootstrap, $args, $bootstrap_sql_file,
29302935
$path_bootstrap_log, $path_bootstrap_log,
29312936
"", { append_log_file => 1 }) != 0 )
29322937

29332938
{
2934-
unlink($init_db_sql_tmp);
29352939
mtr_error("Error executing mysqld --bootstrap\n" .
2936-
"Could not install $type test DBs");
2940+
"Could not install system database, see $path_bootstrap_log");
29372941
}
2938-
unlink($init_db_sql_tmp);
29392942
}
29402943

29412944

mysql-test/r/create.result

+2
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,11 @@ drop database mysqltest;
509509
select database();
510510
database()
511511
NULL
512+
create user mysqltest_1;
512513
select database(), user();
513514
database() user()
514515
NULL mysqltest_1@localhost
516+
drop user mysqltest_1;
515517
use test;
516518
create table t1 (a int, index `primary` (a));
517519
ERROR 42000: Incorrect index name 'primary'

mysql-test/r/derived.result

+2
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ drop table t1,t2;
202202
SELECT a.x FROM (SELECT 1 AS x) AS a HAVING a.x = 1;
203203
x
204204
1
205+
create user mysqltest_1;
205206
create table t1 select 1 as a;
206207
select 2 as a from (select * from t1) b;
207208
ERROR 3D000: No database selected
@@ -380,3 +381,4 @@ ID DATA FID
380381
select t2.* from (select * from t1) as A inner join t2 on A.ID = t2.FID;
381382
ID DATA FID
382383
drop table t1, t2;
384+
drop user mysqltest_1;

mysql-test/r/join.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ select * from information_schema.statistics join information_schema.columns
701701
using(table_name,column_name) where table_name='user';
702702
TABLE_NAME COLUMN_NAME TABLE_CATALOG TABLE_SCHEMA NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT TABLE_CATALOG TABLE_SCHEMA ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA PRIVILEGES COLUMN_COMMENT
703703
user Host NULL mysql 0 mysql PRIMARY 1 A NULL NULL NULL BTREE NULL mysql 1 NO char 60 180 NULL NULL utf8 utf8_bin char(60) PRI #
704-
user User NULL mysql 0 mysql PRIMARY 2 A 5 NULL NULL BTREE NULL mysql 2 NO char 16 48 NULL NULL utf8 utf8_bin char(16) PRI #
704+
user User NULL mysql 0 mysql PRIMARY 2 A 3 NULL NULL BTREE NULL mysql 2 NO char 16 48 NULL NULL utf8 utf8_bin char(16) PRI #
705705
drop table t1;
706706
drop table t2;
707707
drop table t3;

mysql-test/r/mysql_upgrade.result

-30
Original file line numberDiff line numberDiff line change
@@ -20,63 +20,43 @@ mysql.user OK
2020
1
2121
1
2222
1
23-
1
24-
1
2523
@hadShowDbPriv:=1
2624
1
2725
1
2826
1
29-
1
30-
1
3127
@hadCreateViewPriv:=1
3228
1
3329
1
3430
1
35-
1
36-
1
3731
@hadCreateRoutinePriv:=1
3832
1
3933
1
4034
1
41-
1
42-
1
4335
@hadCreateUserPriv:=1
4436
1
4537
1
4638
1
47-
1
48-
1
4939
Run it again - should say already completed
5040
@hadGrantPriv:=1
5141
1
5242
1
5343
1
54-
1
55-
1
5644
@hadShowDbPriv:=1
5745
1
5846
1
5947
1
60-
1
61-
1
6248
@hadCreateViewPriv:=1
6349
1
6450
1
6551
1
66-
1
67-
1
6852
@hadCreateRoutinePriv:=1
6953
1
7054
1
7155
1
72-
1
73-
1
7456
@hadCreateUserPriv:=1
7557
1
7658
1
7759
1
78-
1
79-
1
8060
Force should run it regardless of wheter it's been run before
8161
mysql.columns_priv OK
8262
mysql.db OK
@@ -99,29 +79,19 @@ mysql.user OK
9979
1
10080
1
10181
1
102-
1
103-
1
10482
@hadShowDbPriv:=1
10583
1
10684
1
10785
1
108-
1
109-
1
11086
@hadCreateViewPriv:=1
11187
1
11288
1
11389
1
114-
1
115-
1
11690
@hadCreateRoutinePriv:=1
11791
1
11892
1
11993
1
120-
1
121-
1
12294
@hadCreateUserPriv:=1
12395
1
12496
1
12597
1
126-
1
127-
1

mysql-test/r/sp-security.result

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ db1_secret
4545
select * from db1_secret.t1;
4646
ERROR 42000: SELECT command denied to user ''@'localhost' for table 't1'
4747
create procedure db1_secret.dummy() begin end;
48-
ERROR 42000: Access denied for user ''@'localhost' to database 'db1_secret'
48+
ERROR 42000: Access denied for user ''@'%' to database 'db1_secret'
4949
drop procedure db1_secret.dummy;
5050
ERROR 42000: PROCEDURE db1_secret.dummy does not exist
5151
select * from t1;
@@ -76,9 +76,9 @@ ERROR 42000: Access denied for user 'user1'@'localhost' to database 'db1_secret'
7676
select db1_secret.db();
7777
ERROR 42000: Access denied for user 'user1'@'localhost' to database 'db1_secret'
7878
call db1_secret.stamp(6);
79-
ERROR 42000: Access denied for user ''@'localhost' to database 'db1_secret'
79+
ERROR 42000: Access denied for user ''@'%' to database 'db1_secret'
8080
select db1_secret.db();
81-
ERROR 42000: Access denied for user ''@'localhost' to database 'db1_secret'
81+
ERROR 42000: Access denied for user ''@'%' to database 'db1_secret'
8282
drop database if exists db2;
8383
create database db2;
8484
use db2;

mysql-test/t/create.test

+3-1
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,14 @@ select database();
406406
drop database mysqltest;
407407
select database();
408408

409-
# Connect without a database
409+
# Connect without a database as user mysqltest_1
410+
create user mysqltest_1;
410411
connect (user1,localhost,mysqltest_1,,*NO-ONE*);
411412
connection user1;
412413
select database(), user();
413414
connection default;
414415
disconnect user1;
416+
drop user mysqltest_1;
415417
use test;
416418

417419
#

mysql-test/t/derived.test

+6-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ SELECT a.x FROM (SELECT 1 AS x) AS a HAVING a.x = 1;
9999
#
100100
# Test for select if database is not selected.
101101
#
102-
# Connect without a database
102+
# Connect without a database as user mysqltest_1
103+
create user mysqltest_1;
103104
create table t1 select 1 as a;
104105
connect (con1,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,$MASTER_MYSOCK);
105106
connection con1;
@@ -271,4 +272,8 @@ select t2.* from ((select * from t1) as A inner join t2 on A.ID = t2.FID);
271272
select t2.* from (select * from t1) as A inner join t2 on A.ID = t2.FID;
272273
drop table t1, t2;
273274

275+
disconnect con1;
276+
connection default;
277+
drop user mysqltest_1;
278+
274279
# End of 4.1 tests

mysql-test/t/grant2.test

+4
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ delete from mysql.user where user like 'mysqltest\_1';
395395
flush privileges;
396396
drop database mysqltest_1;
397397

398+
--source include/add_anonymous_users.inc
399+
398400
# But anonymous users can't change their password
399401
connect (n5,localhost,test,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
400402
connection n5;
@@ -403,6 +405,8 @@ set password = password("changed");
403405
disconnect n5;
404406
connection default;
405407

408+
--source include/delete_anonymous_users.inc
409+
406410

407411
# Bug #12423 "Deadlock when doing FLUSH PRIVILEGES and GRANT in
408412
# multi-threaded environment". We should be able to execute FLUSH

mysql-test/t/grant_cache.test

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
-- source include/not_embedded.inc
33
-- source include/have_query_cache.inc
44

5+
--source include/add_anonymous_users.inc
6+
57
#
68
# Test grants with query cache
79
#
@@ -71,6 +73,7 @@ show status like "Qcache_queries_in_cache";
7173
show status like "Qcache_hits";
7274
show status like "Qcache_not_cached";
7375

76+
7477
# Don't use '' as user because it will pick Unix login
7578
connect (unkuser,localhost,unkuser,,,$MASTER_MYPORT,$MASTER_MYSOCK);
7679
connection unkuser;
@@ -150,4 +153,7 @@ drop database mysqltest;
150153

151154
set GLOBAL query_cache_size=default;
152155

156+
--source include/delete_anonymous_users.inc
157+
158+
153159
# End of 4.1 tests

0 commit comments

Comments
 (0)