1
1
/*
2
2
Copyright (c) 2006, 2013, Oracle and/or its affiliates.
3
- Copyright (c) 2010, 2013, Monty Program Ab.
3
+ Copyright (c) 2010, 2015, MariaDB
4
4
5
5
This program is free software; you can redistribute it and/or modify
6
6
it under the terms of the GNU General Public License as published by
36
36
# endif
37
37
#endif
38
38
39
+ static int phase = 0 ;
40
+ static int phases_total = 6 ;
39
41
static char mysql_path [FN_REFLEN ];
40
42
static char mysqlcheck_path [FN_REFLEN ];
41
43
@@ -45,6 +47,8 @@ static my_bool opt_not_used, opt_silent;
45
47
static uint my_end_arg = 0 ;
46
48
static char * opt_user = (char * )"root" ;
47
49
50
+ static my_bool upgrade_from_mysql ;
51
+
48
52
static DYNAMIC_STRING ds_args ;
49
53
static DYNAMIC_STRING conn_args ;
50
54
@@ -206,12 +210,12 @@ static void die(const char *fmt, ...)
206
210
}
207
211
208
212
209
- static int verbose (const char * fmt , ...)
213
+ static void verbose (const char * fmt , ...)
210
214
{
211
215
va_list args ;
212
216
213
217
if (opt_silent )
214
- return 0 ;
218
+ return ;
215
219
216
220
/* Print the verbose message */
217
221
va_start (args , fmt );
@@ -222,7 +226,6 @@ static int verbose(const char *fmt, ...)
222
226
fflush (stdout );
223
227
}
224
228
va_end (args );
225
- return 0 ;
226
229
}
227
230
228
231
@@ -740,10 +743,21 @@ static void print_conn_args(const char *tool_name)
740
743
in the server using "mysqlcheck --check-upgrade .."
741
744
*/
742
745
743
- static int run_mysqlcheck_upgrade (const char * arg1 , const char * arg2 )
746
+ static int run_mysqlcheck_upgrade (my_bool mysql_db_only )
744
747
{
748
+ const char * what = mysql_db_only ? "mysql database" : "tables" ;
749
+ const char * arg1 = mysql_db_only ? "--databases" : "--all-databases" ;
750
+ const char * arg2 = mysql_db_only ? "mysql" : "--skip-database=mysql" ;
751
+ int retch ;
752
+ if (opt_systables_only && !mysql_db_only )
753
+ {
754
+ verbose ("Phase %d/%d: Checking and upgrading %s... Skipped" ,
755
+ ++ phase , phases_total , what );
756
+ return 0 ;
757
+ }
758
+ verbose ("Phase %d/%d: Checking and upgrading %s" , ++ phase , phases_total , what );
745
759
print_conn_args ("mysqlcheck" );
746
- return run_tool (mysqlcheck_path ,
760
+ retch = run_tool (mysqlcheck_path ,
747
761
NULL , /* Send output from mysqlcheck directly to screen */
748
762
"--no-defaults" ,
749
763
ds_args .str ,
@@ -757,12 +771,77 @@ static int run_mysqlcheck_upgrade(const char *arg1, const char *arg2)
757
771
arg1 , arg2 ,
758
772
"2>&1" ,
759
773
NULL );
774
+ return retch ;
760
775
}
761
776
777
+ #define EVENTS_STRUCT_LEN 7000
778
+
779
+ static my_bool is_mysql ()
780
+ {
781
+ my_bool ret = TRUE;
782
+ DYNAMIC_STRING ds_events_struct ;
783
+
784
+ if (init_dynamic_string (& ds_events_struct , NULL ,
785
+ EVENTS_STRUCT_LEN , EVENTS_STRUCT_LEN ))
786
+ die ("Out of memory" );
787
+
788
+ if (run_query ("show create table mysql.event" ,
789
+ & ds_events_struct , FALSE) ||
790
+ strstr (ds_events_struct .str , "IGNORE_BAD_TABLE_OPTIONS" ) != NULL )
791
+ ret = FALSE;
792
+ else
793
+ verbose ("MySQL upgrade detected" );
794
+
795
+ dynstr_free (& ds_events_struct );
796
+ return (ret );
797
+ }
798
+
799
+ static int run_mysqlcheck_views (void )
800
+ {
801
+ const char * upgrade_views = "--process-views=YES" ;
802
+ if (upgrade_from_mysql )
803
+ {
804
+ /*
805
+ this has to ignore opt_systables_only, because upgrade_from_mysql
806
+ is determined by analyzing systables. if we honor opt_systables_only
807
+ here, views won't be fixed by subsequent mysql_upgrade runs
808
+ */
809
+ upgrade_views = "--process-views=UPGRADE_FROM_MYSQL" ;
810
+ verbose ("Phase %d/%d: Fixing views from mysql" , ++ phase , phases_total );
811
+ }
812
+ else if (opt_systables_only )
813
+ {
814
+ verbose ("Phase %d/%d: Fixing views... Skipped" , ++ phase , phases_total );
815
+ return 0 ;
816
+ }
817
+ else
818
+ verbose ("Phase %d/%d: Fixing views" , ++ phase , phases_total );
819
+
820
+ print_conn_args ("mysqlcheck" );
821
+ return run_tool (mysqlcheck_path ,
822
+ NULL , /* Send output from mysqlcheck directly to screen */
823
+ "--no-defaults" ,
824
+ ds_args .str ,
825
+ "--all-databases" , "--repair" ,
826
+ upgrade_views ,
827
+ "--skip-process-tables" ,
828
+ opt_verbose ? "--verbose" : "" ,
829
+ opt_silent ? "--silent" : "" ,
830
+ opt_write_binlog ? "--write-binlog" : "--skip-write-binlog" ,
831
+ "2>&1" ,
832
+ NULL );
833
+ }
762
834
763
835
static int run_mysqlcheck_fixnames (void )
764
836
{
765
- verbose ("Phase 3/5: Fixing table and database names" );
837
+ if (opt_systables_only )
838
+ {
839
+ verbose ("Phase %d/%d: Fixing table and database names ... Skipped" ,
840
+ ++ phase , phases_total );
841
+ return 0 ;
842
+ }
843
+ verbose ("Phase %d/%d: Fixing table and database names" ,
844
+ ++ phase , phases_total );
766
845
print_conn_args ("mysqlcheck" );
767
846
return run_tool (mysqlcheck_path ,
768
847
NULL , /* Send output from mysqlcheck directly to screen */
@@ -850,6 +929,9 @@ static int run_sql_fix_privilege_tables(void)
850
929
if (init_dynamic_string (& ds_result , "" , 512 , 512 ))
851
930
die ("Out of memory" );
852
931
932
+ verbose ("Phase %d/%d: Running 'mysql_fix_privilege_tables'" ,
933
+ ++ phase , phases_total );
934
+
853
935
/*
854
936
Individual queries can not be executed independently by invoking
855
937
a forked mysql client, because the script uses session variables
@@ -1019,23 +1101,19 @@ int main(int argc, char **argv)
1019
1101
if (opt_version_check && check_version_match ())
1020
1102
die ("Upgrade failed" );
1021
1103
1104
+ upgrade_from_mysql = is_mysql ();
1105
+
1022
1106
/*
1023
1107
Run "mysqlcheck" and "mysql_fix_privilege_tables.sql"
1024
1108
*/
1025
- verbose ( "Phase 1/5: Checking mysql database" );
1026
- if ( run_mysqlcheck_upgrade ( "--databases" , "mysql" ))
1027
- die ( "Upgrade failed" );
1028
- verbose ( "Phase 2/5: Running 'mysql_fix_privilege_tables'..." );
1029
- if ( run_sql_fix_privilege_tables ( ))
1109
+ if ( run_mysqlcheck_upgrade (TRUE) ||
1110
+ run_mysqlcheck_views () ||
1111
+ run_sql_fix_privilege_tables () ||
1112
+ run_mysqlcheck_fixnames () ||
1113
+ run_mysqlcheck_upgrade (FALSE ))
1030
1114
die ("Upgrade failed" );
1031
1115
1032
- if (!opt_systables_only &&
1033
- (run_mysqlcheck_fixnames () ||
1034
- verbose ("Phase 4/5: Checking and upgrading tables" ) ||
1035
- run_mysqlcheck_upgrade ("--all-databases" ,"--skip-database=mysql" )))
1036
- die ("Upgrade failed" );
1037
-
1038
- verbose ("Phase 5/5: Running 'FLUSH PRIVILEGES'..." );
1116
+ verbose ("Phase %d/%d: Running 'FLUSH PRIVILEGES'" , ++ phase , phases_total );
1039
1117
if (run_query ("FLUSH PRIVILEGES" , NULL , TRUE))
1040
1118
die ("Upgrade failed" );
1041
1119
@@ -1044,6 +1122,8 @@ int main(int argc, char **argv)
1044
1122
/* Create a file indicating upgrade has been performed */
1045
1123
create_mysql_upgrade_info_file ();
1046
1124
1125
+ DBUG_ASSERT (phase == phases_total );
1126
+
1047
1127
free_used_memory ();
1048
1128
my_end (my_end_arg );
1049
1129
exit (0 );
0 commit comments