30
30
** master/autocommit code by Brian Aker <brian@tangent.org>
31
31
** SSL by
32
32
** Andrei Errapart <andreie@no.spam.ee>
33
- ** Tõnu Samuel <tonu@please.do.not.remove.this.spam.ee>
33
+ ** Tõnu Samuel <tonu@please.do.not.remove.this.spam.ee>
34
34
** XML by Gary Huntress <ghuntress@mediaone.net> 10/10/01, cleaned up
35
35
** and adapted to mysqldump 05/11/01 by Jani Tolonen
36
36
** Added --single-transaction option 06/06/2002 by Peter Zaitsev
37
37
** 10 Jun 2003: SET NAMES and --no-set-names by Alexander Barkov
38
38
*/
39
39
40
- #define DUMP_VERSION "10.10 "
40
+ #define DUMP_VERSION "10.11 "
41
41
42
42
#include <my_global.h>
43
43
#include <my_sys.h>
@@ -103,14 +103,15 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
103
103
opt_alltspcs = 0 ;
104
104
static ulong opt_max_allowed_packet , opt_net_buffer_length ;
105
105
static MYSQL mysql_connection ,* mysql = 0 ;
106
- static my_bool insert_pat_inited = 0 ;
106
+ static my_bool insert_pat_inited = 0 , info_flag ;
107
107
static DYNAMIC_STRING insert_pat ;
108
108
static char * opt_password = 0 ,* current_user = 0 ,
109
109
* current_host = 0 ,* path = 0 ,* fields_terminated = 0 ,
110
110
* lines_terminated = 0 , * enclosed = 0 , * opt_enclosed = 0 , * escaped = 0 ,
111
111
* where = 0 , * order_by = 0 ,
112
112
* opt_compatible_mode_str = 0 ,
113
113
* err_ptr = 0 ;
114
+ static char * * defaults_argv = 0 ;
114
115
static char compatible_mode_normal_str [255 ];
115
116
static ulong opt_compatible_mode = 0 ;
116
117
#define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1
@@ -120,7 +121,7 @@ static my_string opt_mysql_unix_port=0;
120
121
static int first_error = 0 ;
121
122
static DYNAMIC_STRING extended_row ;
122
123
#include <sslopt-vars.h>
123
- FILE * md_result_file ;
124
+ FILE * md_result_file = 0 ;
124
125
#ifdef HAVE_SMEM
125
126
static char * shared_memory_base_name = 0 ;
126
127
#endif
@@ -222,6 +223,8 @@ static struct my_option my_long_options[] =
222
223
{"debug" , '#' , "Output debug log" , (gptr * ) & default_dbug_option ,
223
224
(gptr * ) & default_dbug_option , 0 , GET_STR , OPT_ARG , 0 , 0 , 0 , 0 , 0 , 0 },
224
225
#endif
226
+ {"debug-info" , OPT_DEBUG_INFO , "Print some debug info at exit." , (gptr * ) & info_flag ,
227
+ (gptr * ) & info_flag , 0 , GET_BOOL , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 },
225
228
{"default-character-set" , OPT_DEFAULT_CHARSET ,
226
229
"Set the default character set." , (gptr * ) & default_charset ,
227
230
(gptr * ) & default_charset , 0 , GET_STR , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 },
@@ -641,14 +644,6 @@ byte* get_table_key(const char *entry, uint *length,
641
644
}
642
645
643
646
644
- void init_table_rule_hash (HASH * h )
645
- {
646
- if (hash_init (h , charset_info , 16 , 0 , 0 ,
647
- (hash_get_key ) get_table_key ,
648
- (hash_free_key ) free_table_ent , 0 ))
649
- exit (EX_EOM );
650
- }
651
-
652
647
static my_bool
653
648
get_one_option (int optid , const struct my_option * opt __attribute__((unused )),
654
649
char * argument )
@@ -691,6 +686,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
691
686
break ;
692
687
case '#' :
693
688
DBUG_PUSH (argument ? argument : default_dbug_option );
689
+ info_flag = 1 ;
694
690
break ;
695
691
#include <sslopt-case.h>
696
692
case 'V' : print_version (); exit (0 );
@@ -731,9 +727,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
731
727
fprintf (stderr , "Illegal use of option --ignore-table=<database>.<table>\n" );
732
728
exit (1 );
733
729
}
734
- if (!hash_inited (& ignore_table ))
735
- init_table_rule_hash (& ignore_table );
736
-
737
730
if (my_hash_insert (& ignore_table , (byte * )my_strdup (argument , MYF (0 ))))
738
731
exit (EX_EOM );
739
732
break ;
@@ -809,9 +802,21 @@ static int get_options(int *argc, char ***argv)
809
802
810
803
md_result_file = stdout ;
811
804
load_defaults ("my" ,load_default_groups ,argc ,argv );
805
+ defaults_argv = * argv ;
812
806
813
- if ((ho_error = handle_options (argc , argv , my_long_options , get_one_option )))
814
- exit (ho_error );
807
+ if (hash_init (& ignore_table , charset_info , 16 , 0 , 0 ,
808
+ (hash_get_key ) get_table_key ,
809
+ (hash_free_key ) free_table_ent , 0 ))
810
+ return (EX_EOM );
811
+ /* Don't copy cluster internal log tables */
812
+ if (my_hash_insert (& ignore_table ,
813
+ (byte * ) my_strdup ("mysql.apply_status" , MYF (MY_WME ))) ||
814
+ my_hash_insert (& ignore_table ,
815
+ (byte * ) my_strdup ("mysql.schema" , MYF (MY_WME ))))
816
+ return (EX_EOM );
817
+
818
+ if ((ho_error = handle_options (argc , argv , my_long_options , get_one_option )))
819
+ return (ho_error );
815
820
816
821
* mysql_params -> p_max_allowed_packet = opt_max_allowed_packet ;
817
822
* mysql_params -> p_net_buffer_length = opt_net_buffer_length ;
@@ -823,7 +828,7 @@ static int get_options(int *argc, char ***argv)
823
828
{
824
829
fprintf (stderr ,
825
830
"%s: You must use option --tab with --fields-...\n" , my_progname );
826
- return (1 );
831
+ return (EX_USAGE );
827
832
}
828
833
829
834
/* Ensure consistency of the set of binlog & locking options */
@@ -833,7 +838,7 @@ static int get_options(int *argc, char ***argv)
833
838
{
834
839
fprintf (stderr , "%s: You can't use --single-transaction and "
835
840
"--lock-all-tables at the same time.\n" , my_progname );
836
- return (1 );
841
+ return (EX_USAGE );
837
842
}
838
843
if (opt_master_data )
839
844
opt_lock_all_tables = !opt_single_transaction ;
@@ -842,14 +847,14 @@ static int get_options(int *argc, char ***argv)
842
847
if (enclosed && opt_enclosed )
843
848
{
844
849
fprintf (stderr , "%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n" , my_progname );
845
- return (1 );
850
+ return (EX_USAGE );
846
851
}
847
852
if ((opt_databases || opt_alldbs ) && path )
848
853
{
849
854
fprintf (stderr ,
850
855
"%s: --databases or --all-databases can't be used with --tab.\n" ,
851
856
my_progname );
852
- return (1 );
857
+ return (EX_USAGE );
853
858
}
854
859
if (strcmp (default_charset , charset_info -> csname ) &&
855
860
!(charset_info = get_charset_by_csname (default_charset ,
@@ -858,7 +863,7 @@ static int get_options(int *argc, char ***argv)
858
863
if ((* argc < 1 && !opt_alldbs ) || (* argc > 0 && opt_alldbs ))
859
864
{
860
865
short_usage ();
861
- return 1 ;
866
+ return EX_USAGE ;
862
867
}
863
868
if (tty_password )
864
869
opt_password = get_tty_password (NullS );
@@ -933,6 +938,23 @@ static FILE* open_sql_file_for_table(const char* table)
933
938
}
934
939
935
940
941
+ static void free_resources ()
942
+ {
943
+ if (md_result_file && md_result_file != stdout )
944
+ my_fclose (md_result_file , MYF (0 ));
945
+ my_free (opt_password , MYF (MY_ALLOW_ZERO_PTR ));
946
+ if (hash_inited (& ignore_table ))
947
+ hash_free (& ignore_table );
948
+ if (extended_insert )
949
+ dynstr_free (& extended_row );
950
+ if (insert_pat_inited )
951
+ dynstr_free (& insert_pat );
952
+ if (defaults_argv )
953
+ free_defaults (defaults_argv );
954
+ my_end (info_flag ? MY_CHECK_ERROR : 0 );
955
+ }
956
+
957
+
936
958
static void safe_exit (int error )
937
959
{
938
960
if (!first_error )
@@ -941,18 +963,19 @@ static void safe_exit(int error)
941
963
return ;
942
964
if (mysql )
943
965
mysql_close (mysql );
966
+ free_resources ();
944
967
exit (error );
945
968
}
946
- /* safe_exit */
947
969
948
970
949
971
/*
950
- ** dbConnect -- connects to the host and selects DB.
972
+ db_connect -- connects to the host and selects DB.
951
973
*/
952
- static int dbConnect (char * host , char * user ,char * passwd )
974
+
975
+ static int connect_to_db (char * host , char * user ,char * passwd )
953
976
{
954
977
char buff [20 + FN_REFLEN ];
955
- DBUG_ENTER ("dbConnect " );
978
+ DBUG_ENTER ("connect_to_db " );
956
979
957
980
verbose_msg ("-- Connecting to %s...\n" , host ? host : "localhost" );
958
981
mysql_init (& mysql_connection );
@@ -973,11 +996,11 @@ static int dbConnect(char *host, char *user,char *passwd)
973
996
#endif
974
997
mysql_options (& mysql_connection , MYSQL_SET_CHARSET_NAME , default_charset );
975
998
if (!(mysql = mysql_real_connect (& mysql_connection ,host ,user ,passwd ,
976
- NULL ,opt_mysql_port ,opt_mysql_unix_port ,
977
- 0 )))
999
+ NULL ,opt_mysql_port ,opt_mysql_unix_port ,
1000
+ 0 )))
978
1001
{
979
1002
DB_error (& mysql_connection , "when trying to connect" );
980
- return 1 ;
1003
+ DBUG_RETURN ( 1 ) ;
981
1004
}
982
1005
/*
983
1006
Don't dump SET NAMES with a pre-4.1 server (bug#7997).
@@ -994,7 +1017,7 @@ static int dbConnect(char *host, char *user,char *passwd)
994
1017
if (mysql_query_with_error_report (mysql , 0 , buff ))
995
1018
{
996
1019
safe_exit (EX_MYSQLERR );
997
- return 1 ;
1020
+ DBUG_RETURN ( 1 ) ;
998
1021
}
999
1022
/*
1000
1023
set time_zone to UTC to allow dumping date types between servers with
@@ -1006,11 +1029,11 @@ static int dbConnect(char *host, char *user,char *passwd)
1006
1029
if (mysql_query_with_error_report (mysql , 0 , buff ))
1007
1030
{
1008
1031
safe_exit (EX_MYSQLERR );
1009
- return 1 ;
1032
+ DBUG_RETURN ( 1 ) ;
1010
1033
}
1011
1034
}
1012
- return 0 ;
1013
- } /* dbConnect */
1035
+ DBUG_RETURN ( 0 ) ;
1036
+ } /* connect_to_db */
1014
1037
1015
1038
1016
1039
/*
@@ -1659,7 +1682,11 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1659
1682
{
1660
1683
complete_insert = opt_complete_insert ;
1661
1684
if (!insert_pat_inited )
1662
- insert_pat_inited = init_dynamic_string (& insert_pat , "" , 1024 , 1024 );
1685
+ {
1686
+ insert_pat_inited = 1 ;
1687
+ if (init_dynamic_string (& insert_pat , "" , 1024 , 1024 ))
1688
+ safe_exit (EX_MYSQLERR );
1689
+ }
1663
1690
else
1664
1691
dynstr_set (& insert_pat , "" );
1665
1692
}
@@ -2134,7 +2161,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
2134
2161
2135
2162
*/
2136
2163
2137
- static void dump_triggers_for_table (char * table , char * db )
2164
+ static void dump_triggers_for_table (char * table , char * db )
2138
2165
{
2139
2166
char * result_table ;
2140
2167
char name_buff [NAME_LEN * 4 + 3 ], table_buff [NAME_LEN * 2 + 3 ];
@@ -2980,6 +3007,8 @@ static int dump_databases(char **db_names)
2980
3007
{
2981
3008
int result = 0 ;
2982
3009
char * * db ;
3010
+ DBUG_ENTER ("dump_databases" );
3011
+
2983
3012
for (db = db_names ; * db ; db ++ )
2984
3013
{
2985
3014
if (dump_all_tables_in_db (* db ))
@@ -2993,7 +3022,7 @@ static int dump_databases(char **db_names)
2993
3022
result = 1 ;
2994
3023
}
2995
3024
}
2996
- return result ;
3025
+ DBUG_RETURN ( result ) ;
2997
3026
} /* dump_databases */
2998
3027
2999
3028
@@ -3008,7 +3037,7 @@ RETURN VALUES
3008
3037
0 Success.
3009
3038
1 Failure.
3010
3039
*/
3011
- int init_dumping_views (char * qdatabase )
3040
+ int init_dumping_views (char * qdatabase __attribute__(( unused )) )
3012
3041
{
3013
3042
return 0 ;
3014
3043
} /* init_dumping_views */
@@ -3105,12 +3134,11 @@ static int init_dumping(char *database, int init_func(char*))
3105
3134
} /* init_dumping */
3106
3135
3107
3136
3137
+ /* Return 1 if we should copy the table */
3138
+
3108
3139
my_bool include_table (byte * hash_key , uint len )
3109
3140
{
3110
- if (hash_search (& ignore_table , (byte * ) hash_key , len ))
3111
- return FALSE;
3112
-
3113
- return TRUE;
3141
+ return !hash_search (& ignore_table , (byte * ) hash_key , len );
3114
3142
}
3115
3143
3116
3144
@@ -3119,10 +3147,10 @@ static int dump_all_tables_in_db(char *database)
3119
3147
char * table ;
3120
3148
uint numrows ;
3121
3149
char table_buff [NAME_LEN * 2 + 3 ];
3122
-
3123
3150
char hash_key [2 * NAME_LEN + 2 ]; /* "db.tablename" */
3124
3151
char * afterdot ;
3125
3152
int using_mysql_db = my_strcasecmp (& my_charset_latin1 , database , "mysql" );
3153
+ DBUG_ENTER ("dump_all_tables_in_db" );
3126
3154
3127
3155
afterdot = strmov (hash_key , database );
3128
3156
* afterdot ++ = '.' ;
@@ -3558,7 +3586,6 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
3558
3586
3559
3587
3560
3588
/*
3561
-
3562
3589
SYNOPSIS
3563
3590
3564
3591
Check if we the table is one of the table types that should be ignored:
@@ -3598,8 +3625,8 @@ char check_if_ignore_table(const char *table_name, char *table_type)
3598
3625
{
3599
3626
if (mysql_errno (mysql ) != ER_PARSE_ERROR )
3600
3627
{ /* If old MySQL version */
3601
- verbose_msg ("-- Warning: Couldn't get status information for " \
3602
- "table %s (%s)\n" , table_name ,mysql_error (mysql ));
3628
+ verbose_msg ("-- Warning: Couldn't get status information for "
3629
+ "table %s (%s)\n" , table_name , mysql_error (mysql ));
3603
3630
DBUG_RETURN (result ); /* assume table is ok */
3604
3631
}
3605
3632
}
@@ -3954,19 +3981,24 @@ static my_bool get_view_structure(char *table, char* db)
3954
3981
3955
3982
int main (int argc , char * * argv )
3956
3983
{
3984
+ int exit_code ;
3957
3985
MY_INIT ("mysqldump" );
3958
3986
3959
3987
compatible_mode_normal_str [0 ]= 0 ;
3960
3988
default_charset = (char * )mysql_universal_client_charset ;
3961
3989
bzero ((char * ) & ignore_table , sizeof (ignore_table ));
3962
3990
3963
- if (get_options (& argc , & argv ))
3991
+ exit_code = get_options (& argc , & argv );
3992
+ if (exit_code )
3964
3993
{
3965
- my_end (0 );
3966
- exit (EX_USAGE );
3994
+ free_resources (0 );
3995
+ exit (exit_code );
3967
3996
}
3968
- if (dbConnect (current_host , current_user , opt_password ))
3997
+ if (connect_to_db (current_host , current_user , opt_password ))
3998
+ {
3999
+ free_resources (0 );
3969
4000
exit (EX_MYSQLERR );
4001
+ }
3970
4002
if (!path )
3971
4003
write_header (md_result_file , * argv );
3972
4004
@@ -4016,15 +4048,6 @@ int main(int argc, char **argv)
4016
4048
dbDisconnect (current_host );
4017
4049
if (!path )
4018
4050
write_footer (md_result_file );
4019
- if (md_result_file != stdout )
4020
- my_fclose (md_result_file , MYF (0 ));
4021
- my_free (opt_password , MYF (MY_ALLOW_ZERO_PTR ));
4022
- if (hash_inited (& ignore_table ))
4023
- hash_free (& ignore_table );
4024
- if (extended_insert )
4025
- dynstr_free (& extended_row );
4026
- if (insert_pat_inited )
4027
- dynstr_free (& insert_pat );
4028
- my_end (0 );
4051
+ free_resources ();
4029
4052
return (first_error );
4030
4053
} /* main */
0 commit comments