1--
2-- PERFORMANCE SCHEMA INSTALLATION
3-- Note that this script is also reused by mysql_upgrade,
4-- so we have to be very careful here to not destroy any
5-- existing database named 'performance_schema' if it
6-- can contain user data.
7-- In case of downgrade, it's ok to drop unknown tables
8-- from a future version, as long as they belong to the
9-- performance schema engine.
10--
11
12set @have_old_pfs= (select count(*) from information_schema.schemata where schema_name='performance_schema');
13
14SET @cmd="SET @broken_tables = (select count(*) from information_schema.tables  where engine != 'PERFORMANCE_SCHEMA' and table_schema='performance_schema')";
15
16-- Work around for bug#49542
17SET @str = IF(@have_old_pfs = 1, @cmd, 'SET @broken_tables = 0');
18PREPARE stmt FROM @str;
19EXECUTE stmt;
20DROP PREPARE stmt;
21
22SET @cmd="SET @broken_views = (select count(*) from information_schema.views where table_schema='performance_schema')";
23
24-- Work around for bug#49542
25SET @str = IF(@have_old_pfs = 1, @cmd, 'SET @broken_views = 0');
26PREPARE stmt FROM @str;
27EXECUTE stmt;
28DROP PREPARE stmt;
29
30SET @broken_routines = (select count(*) from mysql.proc where db='performance_schema');
31
32SET @broken_events = (select count(*) from mysql.event where db='performance_schema');
33
34SET @broken_pfs= (select @broken_tables + @broken_views + @broken_routines + @broken_events);
35
36--
37-- The performance schema database.
38-- Only drop and create the database if this is safe (no broken_pfs).
39-- This database is created, even in --without-perfschema builds,
40-- so that the database name is always reserved by the MySQL implementation.
41--
42
43SET @cmd= "DROP DATABASE IF EXISTS performance_schema";
44
45SET @str = IF(@broken_pfs = 0, @cmd, 'SET @dummy = 0');
46PREPARE stmt FROM @str;
47EXECUTE stmt;
48DROP PREPARE stmt;
49
50SET @cmd= "CREATE DATABASE performance_schema character set utf8";
51
52SET @str = IF(@broken_pfs = 0, @cmd, 'SET @dummy = 0');
53PREPARE stmt FROM @str;
54EXECUTE stmt;
55DROP PREPARE stmt;
56