Commit 51f7f7f4 authored by Marc Alff's avatar Marc Alff

Bug#45194 mysql_upgrade deletes existing data in performance_schema database/schema

Before this fix, mysql_upgrade would always drop and re create
the performance_schema database.
This in theory could destroy user data created using 5.1 or older versions.

With this fix, mysql_upgrade checks the content of the
performance_schema database before droping it.
parent 2155847a
drop table if exists test.user_table;
drop procedure if exists test.user_proc;
drop function if exists test.user_func;
drop event if exists test.user_event;
"Testing mysql_upgrade with TABLE performance_schema.user_table"
create table test.user_table(a int);
use performance_schema;
show tables like "user_table";
Tables_in_performance_schema (user_table)
user_table
ERROR 1644 (HY000) at line 178: Unexpected content found in the performance_schema database.
ERROR 1050 (42S01) at line 203: Table 'COND_INSTANCES' already exists
ERROR 1050 (42S01) at line 233: Table 'EVENTS_WAITS_CURRENT' already exists
ERROR 1050 (42S01) at line 247: Table 'EVENTS_WAITS_HISTORY' already exists
ERROR 1050 (42S01) at line 261: Table 'EVENTS_WAITS_HISTORY_LONG' already exists
ERROR 1050 (42S01) at line 281: Table 'EVENTS_WAITS_SUMMARY_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 302: Table 'EVENTS_WAITS_SUMMARY_BY_INSTANCE' already exists
ERROR 1050 (42S01) at line 323: Table 'EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 340: Table 'FILE_INSTANCES' already exists
ERROR 1050 (42S01) at line 359: Table 'FILE_SUMMARY_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 379: Table 'FILE_SUMMARY_BY_INSTANCE' already exists
ERROR 1050 (42S01) at line 396: Table 'MUTEX_INSTANCES' already exists
ERROR 1050 (42S01) at line 414: Table 'PERFORMANCE_TIMERS' already exists
ERROR 1050 (42S01) at line 431: Table 'PROCESSLIST' already exists
ERROR 1050 (42S01) at line 449: Table 'RWLOCK_INSTANCES' already exists
ERROR 1050 (42S01) at line 465: Table 'SETUP_CONSUMERS' already exists
ERROR 1050 (42S01) at line 482: Table 'SETUP_INSTRUMENTS' already exists
ERROR 1050 (42S01) at line 502: Table 'SETUP_OBJECTS' already exists
ERROR 1050 (42S01) at line 518: Table 'SETUP_TIMERS' already exists
FATAL ERROR: Upgrade failed
show tables like "user_table";
Tables_in_performance_schema (user_table)
user_table
use test;
drop table test.user_table;
"Testing mysql_upgrade with VIEW performance_schema.user_view"
create view test.user_view as select "Not supposed to be here";
use performance_schema;
show tables like "user_view";
Tables_in_performance_schema (user_view)
user_view
ERROR 1644 (HY000) at line 178: Unexpected content found in the performance_schema database.
ERROR 1050 (42S01) at line 203: Table 'COND_INSTANCES' already exists
ERROR 1050 (42S01) at line 233: Table 'EVENTS_WAITS_CURRENT' already exists
ERROR 1050 (42S01) at line 247: Table 'EVENTS_WAITS_HISTORY' already exists
ERROR 1050 (42S01) at line 261: Table 'EVENTS_WAITS_HISTORY_LONG' already exists
ERROR 1050 (42S01) at line 281: Table 'EVENTS_WAITS_SUMMARY_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 302: Table 'EVENTS_WAITS_SUMMARY_BY_INSTANCE' already exists
ERROR 1050 (42S01) at line 323: Table 'EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 340: Table 'FILE_INSTANCES' already exists
ERROR 1050 (42S01) at line 359: Table 'FILE_SUMMARY_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 379: Table 'FILE_SUMMARY_BY_INSTANCE' already exists
ERROR 1050 (42S01) at line 396: Table 'MUTEX_INSTANCES' already exists
ERROR 1050 (42S01) at line 414: Table 'PERFORMANCE_TIMERS' already exists
ERROR 1050 (42S01) at line 431: Table 'PROCESSLIST' already exists
ERROR 1050 (42S01) at line 449: Table 'RWLOCK_INSTANCES' already exists
ERROR 1050 (42S01) at line 465: Table 'SETUP_CONSUMERS' already exists
ERROR 1050 (42S01) at line 482: Table 'SETUP_INSTRUMENTS' already exists
ERROR 1050 (42S01) at line 502: Table 'SETUP_OBJECTS' already exists
ERROR 1050 (42S01) at line 518: Table 'SETUP_TIMERS' already exists
FATAL ERROR: Upgrade failed
show tables like "user_view";
Tables_in_performance_schema (user_view)
user_view
use test;
drop view test.user_view;
"Testing mysql_upgrade with PROCEDURE performance_schema.user_proc"
create procedure test.user_proc()
select "Not supposed to be here";
update mysql.proc set db='performance_schema' where name='user_proc';
ERROR 1644 (HY000) at line 178: Unexpected content found in the performance_schema database.
ERROR 1050 (42S01) at line 203: Table 'COND_INSTANCES' already exists
ERROR 1050 (42S01) at line 233: Table 'EVENTS_WAITS_CURRENT' already exists
ERROR 1050 (42S01) at line 247: Table 'EVENTS_WAITS_HISTORY' already exists
ERROR 1050 (42S01) at line 261: Table 'EVENTS_WAITS_HISTORY_LONG' already exists
ERROR 1050 (42S01) at line 281: Table 'EVENTS_WAITS_SUMMARY_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 302: Table 'EVENTS_WAITS_SUMMARY_BY_INSTANCE' already exists
ERROR 1050 (42S01) at line 323: Table 'EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 340: Table 'FILE_INSTANCES' already exists
ERROR 1050 (42S01) at line 359: Table 'FILE_SUMMARY_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 379: Table 'FILE_SUMMARY_BY_INSTANCE' already exists
ERROR 1050 (42S01) at line 396: Table 'MUTEX_INSTANCES' already exists
ERROR 1050 (42S01) at line 414: Table 'PERFORMANCE_TIMERS' already exists
ERROR 1050 (42S01) at line 431: Table 'PROCESSLIST' already exists
ERROR 1050 (42S01) at line 449: Table 'RWLOCK_INSTANCES' already exists
ERROR 1050 (42S01) at line 465: Table 'SETUP_CONSUMERS' already exists
ERROR 1050 (42S01) at line 482: Table 'SETUP_INSTRUMENTS' already exists
ERROR 1050 (42S01) at line 502: Table 'SETUP_OBJECTS' already exists
ERROR 1050 (42S01) at line 518: Table 'SETUP_TIMERS' already exists
FATAL ERROR: Upgrade failed
select name from mysql.proc where db='performance_schema';
name
user_proc
update mysql.proc set db='test' where name='user_proc';
drop procedure test.user_proc;
"Testing mysql_upgrade with FUNCTION performance_schema.user_func"
create function test.user_func() returns integer
return 0;
update mysql.proc set db='performance_schema' where name='user_func';
ERROR 1644 (HY000) at line 178: Unexpected content found in the performance_schema database.
ERROR 1050 (42S01) at line 203: Table 'COND_INSTANCES' already exists
ERROR 1050 (42S01) at line 233: Table 'EVENTS_WAITS_CURRENT' already exists
ERROR 1050 (42S01) at line 247: Table 'EVENTS_WAITS_HISTORY' already exists
ERROR 1050 (42S01) at line 261: Table 'EVENTS_WAITS_HISTORY_LONG' already exists
ERROR 1050 (42S01) at line 281: Table 'EVENTS_WAITS_SUMMARY_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 302: Table 'EVENTS_WAITS_SUMMARY_BY_INSTANCE' already exists
ERROR 1050 (42S01) at line 323: Table 'EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 340: Table 'FILE_INSTANCES' already exists
ERROR 1050 (42S01) at line 359: Table 'FILE_SUMMARY_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 379: Table 'FILE_SUMMARY_BY_INSTANCE' already exists
ERROR 1050 (42S01) at line 396: Table 'MUTEX_INSTANCES' already exists
ERROR 1050 (42S01) at line 414: Table 'PERFORMANCE_TIMERS' already exists
ERROR 1050 (42S01) at line 431: Table 'PROCESSLIST' already exists
ERROR 1050 (42S01) at line 449: Table 'RWLOCK_INSTANCES' already exists
ERROR 1050 (42S01) at line 465: Table 'SETUP_CONSUMERS' already exists
ERROR 1050 (42S01) at line 482: Table 'SETUP_INSTRUMENTS' already exists
ERROR 1050 (42S01) at line 502: Table 'SETUP_OBJECTS' already exists
ERROR 1050 (42S01) at line 518: Table 'SETUP_TIMERS' already exists
FATAL ERROR: Upgrade failed
select name from mysql.proc where db='performance_schema';
name
user_func
update mysql.proc set db='test' where name='user_func';
drop function test.user_func;
"Testing mysql_upgrade with EVENT performance_schema.user_event"
create event test.user_event on schedule every 1 day do
select "not supposed to be here";
update mysql.event set db='performance_schema' where name='user_event';
ERROR 1644 (HY000) at line 178: Unexpected content found in the performance_schema database.
ERROR 1050 (42S01) at line 203: Table 'COND_INSTANCES' already exists
ERROR 1050 (42S01) at line 233: Table 'EVENTS_WAITS_CURRENT' already exists
ERROR 1050 (42S01) at line 247: Table 'EVENTS_WAITS_HISTORY' already exists
ERROR 1050 (42S01) at line 261: Table 'EVENTS_WAITS_HISTORY_LONG' already exists
ERROR 1050 (42S01) at line 281: Table 'EVENTS_WAITS_SUMMARY_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 302: Table 'EVENTS_WAITS_SUMMARY_BY_INSTANCE' already exists
ERROR 1050 (42S01) at line 323: Table 'EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 340: Table 'FILE_INSTANCES' already exists
ERROR 1050 (42S01) at line 359: Table 'FILE_SUMMARY_BY_EVENT_NAME' already exists
ERROR 1050 (42S01) at line 379: Table 'FILE_SUMMARY_BY_INSTANCE' already exists
ERROR 1050 (42S01) at line 396: Table 'MUTEX_INSTANCES' already exists
ERROR 1050 (42S01) at line 414: Table 'PERFORMANCE_TIMERS' already exists
ERROR 1050 (42S01) at line 431: Table 'PROCESSLIST' already exists
ERROR 1050 (42S01) at line 449: Table 'RWLOCK_INSTANCES' already exists
ERROR 1050 (42S01) at line 465: Table 'SETUP_CONSUMERS' already exists
ERROR 1050 (42S01) at line 482: Table 'SETUP_INSTRUMENTS' already exists
ERROR 1050 (42S01) at line 502: Table 'SETUP_OBJECTS' already exists
ERROR 1050 (42S01) at line 518: Table 'SETUP_TIMERS' already exists
FATAL ERROR: Upgrade failed
select name from mysql.event where db='performance_schema';
name
user_event
update mysql.event set db='test' where name='user_event';
drop event test.user_event;
# Copyright (C) 2010 Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Tests for PERFORMANCE_SCHEMA
# Make sure mysql_upgrade does not destroy data in a 'performance_schema'
# database.
#
--source include/not_embedded.inc
--source include/have_perfschema.inc
--disable_warnings
drop table if exists test.user_table;
drop procedure if exists test.user_proc;
drop function if exists test.user_func;
drop event if exists test.user_event;
--enable_warnings
--echo "Testing mysql_upgrade with TABLE performance_schema.user_table"
create table test.user_table(a int);
let $MYSQLD_DATADIR= `SELECT @@datadir`;
--copy_file $MYSQLD_DATADIR/test/user_table.frm $MYSQLD_DATADIR/performance_schema/user_table.frm
# Make sure the table is visible
use performance_schema;
show tables like "user_table";
--error 1
--exec $MYSQL_UPGRADE --skip-verbose > $MYSQLTEST_VARDIR/tmp/pfs_upgrade.out 2> $MYSQLTEST_VARDIR/tmp/pfs_upgrade.err
# Verify that mysql_upgrade complained about the performance_schema
--cat_file $MYSQLTEST_VARDIR/tmp/pfs_upgrade.err
# Make sure the table is still visible
show tables like "user_table";
use test;
--remove_file $MYSQLD_DATADIR/performance_schema/user_table.frm
drop table test.user_table;
--echo "Testing mysql_upgrade with VIEW performance_schema.user_view"
create view test.user_view as select "Not supposed to be here";
let $MYSQLD_DATADIR= `SELECT @@datadir`;
--copy_file $MYSQLD_DATADIR/test/user_view.frm $MYSQLD_DATADIR/performance_schema/user_view.frm
# Make sure the view is visible
use performance_schema;
show tables like "user_view";
--error 1
--exec $MYSQL_UPGRADE --skip-verbose > $MYSQLTEST_VARDIR/tmp/pfs_upgrade.out 2> $MYSQLTEST_VARDIR/tmp/pfs_upgrade.err
# Verify that mysql_upgrade complained about the performance_schema
--cat_file $MYSQLTEST_VARDIR/tmp/pfs_upgrade.err
# Make sure the view is still visible
show tables like "user_view";
use test;
--remove_file $MYSQLD_DATADIR/performance_schema/user_view.frm
drop view test.user_view;
--echo "Testing mysql_upgrade with PROCEDURE performance_schema.user_proc"
create procedure test.user_proc()
select "Not supposed to be here";
update mysql.proc set db='performance_schema' where name='user_proc';
--error 1
--exec $MYSQL_UPGRADE --skip-verbose > $MYSQLTEST_VARDIR/tmp/pfs_upgrade.out 2> $MYSQLTEST_VARDIR/tmp/pfs_upgrade.err
# Verify that mysql_upgrade complained about the performance_schema
--cat_file $MYSQLTEST_VARDIR/tmp/pfs_upgrade.err
select name from mysql.proc where db='performance_schema';
update mysql.proc set db='test' where name='user_proc';
drop procedure test.user_proc;
--echo "Testing mysql_upgrade with FUNCTION performance_schema.user_func"
create function test.user_func() returns integer
return 0;
update mysql.proc set db='performance_schema' where name='user_func';
--error 1
--exec $MYSQL_UPGRADE --skip-verbose > $MYSQLTEST_VARDIR/tmp/pfs_upgrade.out 2> $MYSQLTEST_VARDIR/tmp/pfs_upgrade.err
# Verify that mysql_upgrade complained about the performance_schema
--cat_file $MYSQLTEST_VARDIR/tmp/pfs_upgrade.err
select name from mysql.proc where db='performance_schema';
update mysql.proc set db='test' where name='user_func';
drop function test.user_func;
--echo "Testing mysql_upgrade with EVENT performance_schema.user_event"
create event test.user_event on schedule every 1 day do
select "not supposed to be here";
update mysql.event set db='performance_schema' where name='user_event';
--error 1
--exec $MYSQL_UPGRADE --skip-verbose > $MYSQLTEST_VARDIR/tmp/pfs_upgrade.out 2> $MYSQLTEST_VARDIR/tmp/pfs_upgrade.err
# Verify that mysql_upgrade complained about the performance_schema
--cat_file $MYSQLTEST_VARDIR/tmp/pfs_upgrade.err
select name from mysql.event where db='performance_schema';
update mysql.event set db='test' where name='user_event';
drop event test.user_event;
--remove_file $MYSQLTEST_VARDIR/tmp/pfs_upgrade.out
--remove_file $MYSQLTEST_VARDIR/tmp/pfs_upgrade.err
-- Copyright (C) 2008-2009 Sun Microsystems, Inc -- Copyright (C) 2008, 2010 Oracle and/or its affiliates. All rights reserved.
-- --
-- This program is free software; you can redistribute it and/or modify -- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by -- it under the terms of the GNU General Public License as published by
...@@ -100,18 +100,92 @@ CREATE TABLE IF NOT EXISTS event ( db char(64) CHARACTER SET utf8 COLLATE utf8_b ...@@ -100,18 +100,92 @@ CREATE TABLE IF NOT EXISTS event ( db char(64) CHARACTER SET utf8 COLLATE utf8_b
CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM; CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM;
--
-- PERFORMANCE SCHEMA INSTALLATION
-- Note that this script is also reused by mysql_upgrade,
-- so we have to be very careful here to not destroy any
-- existing database named 'performance_schema' if it
-- can contain user data.
-- In case of downgrade, it's ok to drop unknown tables
-- from a future version, as long as they belong to the
-- performance schema engine.
--
set @have_old_pfs= (select count(*) from information_schema.schemata where schema_name='performance_schema');
SET @l1="SET @broken_tables = (select count(*) from information_schema.tables";
SET @l2=" where engine != \'PERFORMANCE_SCHEMA\' and table_schema=\'performance_schema\')";
SET @cmd=concat(@l1,@l2);
-- Work around for bug#49542
SET @str = IF(@have_old_pfs = 1, @cmd, 'SET @broken_tables = 0');
PREPARE stmt FROM @str;
EXECUTE stmt;
DROP PREPARE stmt;
SET @l1="SET @broken_views = (select count(*) from information_schema.views";
SET @l2=" where table_schema='performance_schema')";
SET @cmd=concat(@l1,@l2);
-- Work around for bug#49542
SET @str = IF(@have_old_pfs = 1, @cmd, 'SET @broken_views = 0');
PREPARE stmt FROM @str;
EXECUTE stmt;
DROP PREPARE stmt;
SET @broken_routines = (select count(*) from mysql.proc where db='performance_schema');
SET @broken_events = (select count(*) from mysql.event where db='performance_schema');
SET @broken_pfs= (select @broken_tables + @broken_views + @broken_routines + @broken_events);
-- --
-- The performance schema database. -- The performance schema database.
-- This database is always created, even in --without-perfschema builds, -- Only drop and create the database if this is safe (no broken_pfs).
-- This database is created, even in --without-perfschema builds,
-- so that the database name is always reserved by the MySQL implementation. -- so that the database name is always reserved by the MySQL implementation.
-- --
set @have_pfs= (select count(engine) from information_schema.engines where engine='PERFORMANCE_SCHEMA' and support != 'NO'); SET @cmd= "DROP DATABASE IF EXISTS performance_schema";
SET @str = IF(@broken_pfs = 0, @cmd, 'SET @dummy = 0');
PREPARE stmt FROM @str;
EXECUTE stmt;
DROP PREPARE stmt;
DROP DATABASE IF EXISTS performance_schema; SET @cmd= "CREATE DATABASE performance_schema character set utf8";
CREATE DATABASE performance_schema character set utf8; SET @str = IF(@broken_pfs = 0, @cmd, 'SET @dummy = 0');
PREPARE stmt FROM @str;
EXECUTE stmt;
DROP PREPARE stmt;
--
-- Unlike 'performance_schema', the 'mysql' database is reserved already,
-- so no user procedure is supposed to be there
--
drop procedure if exists mysql.die;
create procedure mysql.die() signal sqlstate 'HY000' set message_text='Unexpected content found in the performance_schema database.';
--
-- For broken upgrades, SIGNAL the error
--
SET @cmd="call mysql.die()";
SET @str = IF(@broken_pfs > 0, @cmd, 'SET @dummy = 0');
PREPARE stmt FROM @str;
EXECUTE stmt;
DROP PREPARE stmt;
drop procedure mysql.die;
--
-- From this point, only create the performance schema tables
-- if the server is build with performance schema
--
set @have_pfs= (select count(engine) from information_schema.engines where engine='PERFORMANCE_SCHEMA' and support != 'NO');
-- --
-- TABLE COND_INSTANCES -- TABLE COND_INSTANCES
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment