diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 97c86024513..cefa1bae6d5 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -2890,8 +2890,6 @@ sub install_db ($$) { mtr_add_arg($args, "--no-defaults"); mtr_add_arg($args, "--bootstrap"); - mtr_add_arg($args, "--console"); - mtr_add_arg($args, "--skip-grant-tables"); mtr_add_arg($args, "--basedir=%s", $path_my_basedir); mtr_add_arg($args, "--datadir=%s", $data_dir); mtr_add_arg($args, "--skip-innodb"); @@ -2918,6 +2916,11 @@ sub install_db ($$) { # --bootstrap, to accommodate this. my $exe_mysqld_bootstrap = $ENV{'MYSQLD_BOOTSTRAP'} || $exe_mysqld; + # ---------------------------------------------------------------------- + # export MYSQLD_BOOTSTRAP_CMD variable containing /mysqld + # ---------------------------------------------------------------------- + $ENV{'MYSQLD_BOOTSTRAP_CMD'}= "$exe_mysqld_bootstrap " . join(" ", @$args); + # Log bootstrap command my $path_bootstrap_log= "$opt_vardir/log/bootstrap.log"; mtr_tofile($path_bootstrap_log, diff --git a/mysql-test/r/bootstrap.result b/mysql-test/r/bootstrap.result new file mode 100644 index 00000000000..3301ca74324 --- /dev/null +++ b/mysql-test/r/bootstrap.result @@ -0,0 +1,8 @@ +drop table if exists t1; +drop table t1; +drop table t1; +ERROR 42S02: Unknown table 't1' +set @my_max_allowed_packet= @@max_allowed_packet; +set global max_allowed_packet=100*@@max_allowed_packet; +set global max_allowed_packet=@my_max_allowed_packet; +drop table t1; diff --git a/mysql-test/t/bootstrap.test b/mysql-test/t/bootstrap.test new file mode 100644 index 00000000000..1c2952e93d0 --- /dev/null +++ b/mysql-test/t/bootstrap.test @@ -0,0 +1,46 @@ +# +# test mysqld in bootstrap mode +# +--disable_warnings +drop table if exists t1; +--enable_warnings + + +# +# Check that --bootstrap reads from stdin +# +--write_file $MYSQLTEST_VARDIR/tmp/bootstrap.sql +use test; +CREATE TABLE t1(a int); +EOF +--exec $MYSQLD_BOOTSTRAP_CMD < $MYSQLTEST_VARDIR/tmp/bootstrap.sql >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1 +drop table t1; + +# +# Check that --bootstrap of file with SQL error returns error +# +--write_file $MYSQLTEST_VARDIR/tmp/bootstrap_error.sql +use test; +CREATE TABLE t1; +EOF +--error 1 +--exec $MYSQLD_BOOTSTRAP_CMD < $MYSQLTEST_VARDIR/tmp/bootstrap_error.sql >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1 +# Table t1 should not exists +--error 1051 +drop table t1; + +# +# Bootstrap with a query larger than 2*thd->net.max_packet +# +set @my_max_allowed_packet= @@max_allowed_packet; +set global max_allowed_packet=100*@@max_allowed_packet; +--disable_query_log +create table t1 select 2 as a, concat(repeat('MySQL', @@max_allowed_packet/10), ';') as b; +eval select * into outfile '$MYSQLTEST_VARDIR/tmp/long_query.sql' from t1; +--enable_query_log +--error 1 +--exec $MYSQLD_BOOTSTRAP_CMD < $MYSQLTEST_VARDIR/tmp/long_query.sql >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1 + +set global max_allowed_packet=@my_max_allowed_packet; +drop table t1; + diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index affa6e130dc..501e0a3dde9 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1308,6 +1308,7 @@ pthread_handler_t handle_bootstrap(void *arg) thd->query= thd->memdup_w_gap(buff, length+1, thd->db_length+1+QUERY_CACHE_FLAGS_SIZE); thd->query[length] = '\0'; + DBUG_PRINT("query",("%-.4096s",thd->query)); /* We don't need to obtain LOCK_thread_count here because in bootstrap mode we have only one thread. @@ -1315,16 +1316,26 @@ pthread_handler_t handle_bootstrap(void *arg) thd->query_id=next_query_id(); mysql_parse(thd,thd->query,length); close_thread_tables(thd); // Free tables + if (thd->is_fatal_error) break; + + if (thd->net.report_error) + { + /* The query failed, send error to log and abort bootstrap */ + net_send_error(thd); + thd->fatal_error(); + break; + } + free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); #ifdef USING_TRANSACTIONS free_root(&thd->transaction.mem_root,MYF(MY_KEEP_PREALLOC)); #endif } - /* thd->fatal_error should be set in case something went wrong */ end: + /* Remember the exit code of bootstrap */ bootstrap_error= thd->is_fatal_error; net_end(&thd->net);