@@ -179,8 +179,6 @@ static uint my_end_arg;
179
179
static char *opt_mysql_unix_port = nullptr ;
180
180
static char *opt_bind_addr = nullptr ;
181
181
static int first_error = 0 ;
182
- static bool opt_dump_users = false ;
183
- static bool opt_add_drop_user = false ;
184
182
#include " client/include/authentication_kerberos_clientopt-vars.h"
185
183
#include " client/include/caching_sha2_passwordopt-vars.h"
186
184
#include " client/include/multi_factor_passwordopt-vars.h"
@@ -252,7 +250,6 @@ const char *default_dbug_option = "d:t:o,/tmp/mysqldump.trace";
252
250
bool seen_views = false ;
253
251
254
252
collation_unordered_set<string> *ignore_table;
255
- collation_unordered_set<string> *exclude_user, *include_user;
256
253
257
254
static struct my_option my_long_options[] = {
258
255
{" all-databases" , ' A' ,
@@ -275,9 +272,6 @@ static struct my_option my_long_options[] = {
275
272
{" add-drop-trigger" , 0 , " Add a DROP TRIGGER before each create." ,
276
273
&opt_drop_trigger, &opt_drop_trigger, nullptr , GET_BOOL, NO_ARG, 0 , 0 , 0 ,
277
274
nullptr , 0 , nullptr },
278
- {" add-drop-user" , 0 , " Add DROP USER when dumping the user definitions" ,
279
- &opt_add_drop_user, &opt_add_drop_user, nullptr , GET_BOOL, OPT_ARG, 0 , 0 ,
280
- 0 , nullptr , 0 , nullptr },
281
275
{" add-locks" , OPT_LOCKS, " Add locks around INSERT statements." , &opt_lock,
282
276
&opt_lock, nullptr , GET_BOOL, NO_ARG, 1 , 0 , 0 , nullptr , 0 , nullptr },
283
277
{" allow-keywords" , OPT_KEYWORDS,
@@ -459,21 +453,6 @@ static struct my_option my_long_options[] = {
459
453
" --ignore-table=database.table." ,
460
454
nullptr , nullptr , nullptr , GET_STR, REQUIRED_ARG, 0 , 0 , 0 , nullptr , 0 ,
461
455
nullptr },
462
- {" exclude-user" , OPT_MYSQLDUMP_EXCLUDE_USER,
463
- " Do not dump the specified user account. To specify more than one user "
464
- " account to exclude, use the directive multiple times, once for each user "
465
- " account. Each user account must be specified with both user and host "
466
- " part, e.g., --exclude-user=foo@localhost." ,
467
- nullptr , nullptr , nullptr , GET_STR, REQUIRED_ARG, 0 , 0 , 0 , nullptr , 0 ,
468
- nullptr },
469
- {" include-user" , OPT_MYSQLDUMP_INCLUDE_USER,
470
- " Dump the specified user account. If no --include-user is specified, dump "
471
- " all user accounts by default. To specify more than one user account to "
472
- " dump, use the directive multiple times, once for each user account. "
473
- " Each user account must be specified with both user and host part, e.g., "
474
- " --exclude-users=foo@localhost." ,
475
- nullptr , nullptr , nullptr , GET_STR, REQUIRED_ARG, 0 , 0 , 0 , nullptr , 0 ,
476
- nullptr },
477
456
{" include-source-host-port" , OPT_MYSQLDUMP_INCLUDE_SOURCE_HOST_PORT,
478
457
" Adds 'SOURCE_HOST=<host>, SOURCE_PORT=<port>' to 'CHANGE REPLICATION "
479
458
" SOURCE TO..' "
@@ -687,11 +666,6 @@ static struct my_option my_long_options[] = {
687
666
{" user" , ' u' , " User for login if not current user." , ¤t_user,
688
667
¤t_user, nullptr , GET_STR, REQUIRED_ARG, 0 , 0 , 0 , nullptr , 0 ,
689
668
nullptr },
690
- {" users" , 0 ,
691
- " Dump user accounts as logical definitions in the form of CREATE USER and "
692
- " GRANT statements. Not compatible with --flush-privileges!" ,
693
- &opt_dump_users, &opt_dump_users, nullptr , GET_BOOL, OPT_ARG, 0 , 0 , 0 ,
694
- nullptr , 0 , nullptr },
695
669
{" verbose" , ' v' , " Print info about the various stages." , &verbose, &verbose,
696
670
nullptr , GET_BOOL, NO_ARG, 0 , 0 , 0 , nullptr , 0 , nullptr },
697
671
{" version" , ' V' , " Output version information and exit." , nullptr , nullptr ,
@@ -793,9 +767,6 @@ static void verbose_msg(const char *fmt, ...)
793
767
MY_ATTRIBUTE((format(printf, 1 , 2 )));
794
768
static char const *fix_identifier_with_newline (char const *object_name,
795
769
bool *freemem);
796
- static bool dump_users (FILE *sql_file);
797
- static bool dump_grants (FILE *sql_file);
798
- static bool fetch_users_list_if_include_is_empty ();
799
770
800
771
static std::unordered_map<string, string> compatibility_rpl_replica_commands = {
801
772
{" SHOW REPLICA STATUS" , " SHOW SLAVE STATUS" },
@@ -1124,23 +1095,7 @@ static bool get_one_option(int optid, const struct my_option *opt,
1124
1095
" Illegal use of option --ignore-table=<database>.<table>\n " );
1125
1096
exit (1 );
1126
1097
}
1127
- ignore_table->emplace (argument);
1128
- break ;
1129
- }
1130
- case (int )OPT_MYSQLDUMP_EXCLUDE_USER: {
1131
- if (!strchr (argument, ' @' )) {
1132
- fprintf (stderr, " Illegal use of option --exclude-user=<user>@<host>\n " );
1133
- exit (1 );
1134
- }
1135
- exclude_user->emplace (argument);
1136
- break ;
1137
- }
1138
- case (int )OPT_MYSQLDUMP_INCLUDE_USER: {
1139
- if (!strchr (argument, ' @' )) {
1140
- fprintf (stderr, " Illegal use of option --include-user=<user>@<host>\n " );
1141
- exit (1 );
1142
- }
1143
- include_user->emplace (argument);
1098
+ ignore_table->insert (argument);
1144
1099
break ;
1145
1100
}
1146
1101
case (int )OPT_COMPATIBLE: {
@@ -1222,10 +1177,6 @@ static int get_options(int *argc, char ***argv) {
1222
1177
1223
1178
ignore_table =
1224
1179
new collation_unordered_set<string>(charset_info, PSI_NOT_INSTRUMENTED);
1225
- exclude_user =
1226
- new collation_unordered_set<string>(charset_info, PSI_NOT_INSTRUMENTED);
1227
- include_user =
1228
- new collation_unordered_set<string>(charset_info, PSI_NOT_INSTRUMENTED);
1229
1180
/* Don't copy internal log tables */
1230
1181
ignore_table->insert (" mysql.apply_status" );
1231
1182
ignore_table->insert (" mysql.schema" );
@@ -1241,47 +1192,6 @@ static int get_options(int *argc, char ***argv) {
1241
1192
&opt_net_buffer_length)) {
1242
1193
exit (1 );
1243
1194
}
1244
- if (opt_dump_users) {
1245
- if (flush_privileges) {
1246
- fprintf (
1247
- stderr,
1248
- " %s: The --users option is incompatible with --flush-privileges\n " ,
1249
- my_progname);
1250
- return (EX_USAGE);
1251
- }
1252
- if (opt_xml) {
1253
- fprintf (stderr, " %s: The --users option is incompatible with --xml\n " ,
1254
- my_progname);
1255
- return (EX_USAGE);
1256
- }
1257
- /* ignore the ACL tables if we are dumping logical ACL */
1258
- ignore_table->insert (" mysql.user" );
1259
- ignore_table->insert (" mysql.global_grants" );
1260
- ignore_table->insert (" mysql.db" );
1261
- ignore_table->insert (" mysql.tables_priv" );
1262
- ignore_table->insert (" mysql.columns_priv" );
1263
- ignore_table->insert (" mysql.procs_priv" );
1264
- ignore_table->insert (" mysql.proxies_priv" );
1265
- ignore_table->insert (" mysql.default_roles" );
1266
- ignore_table->insert (" mysql.role_edges" );
1267
- ignore_table->insert (" mysql.password_history" );
1268
- } else {
1269
- if (include_user->size () > 0 ) {
1270
- fprintf (stderr,
1271
- " %s: The --include-user option is a no-op without --users\n " ,
1272
- my_progname);
1273
- }
1274
- if (exclude_user->size () > 0 ) {
1275
- fprintf (stderr,
1276
- " %s: The --exclude-user option is a no-op without --users\n " ,
1277
- my_progname);
1278
- }
1279
- if (opt_add_drop_user) {
1280
- fprintf (stderr,
1281
- " %s: The --add-drop-user option is a no-op without --users\n " ,
1282
- my_progname);
1283
- }
1284
- }
1285
1195
1286
1196
if (debug_info_flag) my_end_arg = MY_CHECK_ERROR | MY_GIVE_INFO;
1287
1197
if (debug_check_flag) my_end_arg = MY_CHECK_ERROR;
@@ -1332,8 +1242,7 @@ static int get_options(int *argc, char ***argv) {
1332
1242
!(charset_info =
1333
1243
get_charset_by_csname (default_charset, MY_CS_PRIMARY, MYF (MY_WME))))
1334
1244
exit (1 );
1335
- if ((*argc < 1 && !opt_alldbs && !opt_dump_users) ||
1336
- (*argc > 0 && opt_alldbs)) {
1245
+ if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs)) {
1337
1246
short_usage ();
1338
1247
return EX_USAGE;
1339
1248
}
@@ -1716,12 +1625,10 @@ static void free_resources() {
1716
1625
if (md_result_file && md_result_file != stdout)
1717
1626
my_fclose (md_result_file, MYF (0 ));
1718
1627
free_passwords ();
1719
- delete ignore_table;
1720
- ignore_table = nullptr ;
1721
- delete include_user;
1722
- include_user = nullptr ;
1723
- delete exclude_user;
1724
- exclude_user = nullptr ;
1628
+ if (ignore_table != nullptr ) {
1629
+ delete ignore_table;
1630
+ ignore_table = nullptr ;
1631
+ }
1725
1632
if (insert_pat_inited) dynstr_free (&insert_pat);
1726
1633
if (opt_ignore_error) my_free (opt_ignore_error);
1727
1634
opt_init_commands.free ();
@@ -4657,8 +4564,6 @@ static int dump_tablespaces_for_databases(char **databases) {
4657
4564
int r;
4658
4565
int i;
4659
4566
4660
- if (databases[0 ] == nullptr ) return 0 ;
4661
-
4662
4567
init_dynamic_string_checked (&where,
4663
4568
" AND TABLESPACE_NAME IN ("
4664
4569
" SELECT DISTINCT TABLESPACE_NAME FROM"
@@ -5246,10 +5151,10 @@ static int dump_all_tables_in_db(char *database) {
5246
5151
" -- Warning: get_table_structure() failed with some internal "
5247
5152
" error for 'slow_log' table\n " );
5248
5153
}
5249
- if (flush_privileges) {
5250
- fprintf (md_result_file, " \n -- \n -- Flush Grant Tables \n -- \n " );
5251
- fprintf (md_result_file, " \n /*! FLUSH PRIVILEGES */; \n " );
5252
- }
5154
+ }
5155
+ if (flush_privileges && using_mysql_db) {
5156
+ fprintf (md_result_file, " \n -- \n -- Flush Grant Tables \n -- \n " );
5157
+ fprintf (md_result_file, " \n /*! FLUSH PRIVILEGES */; \n " );
5253
5158
}
5254
5159
return 0 ;
5255
5160
} /* dump_all_tables_in_db */
@@ -6467,86 +6372,6 @@ static bool get_view_structure(char *table, char *db) {
6467
6372
return false ;
6468
6373
}
6469
6374
6470
- static bool fetch_users_list_if_include_is_empty () {
6471
- if (include_user->size () != 0 ) return false ;
6472
-
6473
- const char *enum_users_query =
6474
- " SELECT CONCAT('\\ '',user,'\\ '@\\ '',host,'\\ ''),"
6475
- " CONCAT(QUOTE(user),'@',QUOTE(host)), CONCAT(user,'@',host)"
6476
- " FROM mysql.user" ;
6477
- MYSQL_RES *enum_users_res;
6478
- MYSQL_ROW enum_users_row;
6479
- if (mysql_query_with_error_report (mysql, &enum_users_res, enum_users_query))
6480
- return true ;
6481
- if (!enum_users_res) return true ;
6482
- auto enum_users_res_guard =
6483
- create_scope_guard ([&] { mysql_free_result (enum_users_res); });
6484
-
6485
- while ((enum_users_row = mysql_fetch_row (enum_users_res)) != nullptr ) {
6486
- const char *user_name;
6487
- if (strcmp (enum_users_row[0 ], enum_users_row[1 ]) ||
6488
- strpbrk (enum_users_row[0 ], " .%- " ))
6489
- user_name = enum_users_row[1 ];
6490
- else
6491
- user_name = enum_users_row[2 ];
6492
- if (exclude_user->find (user_name) == exclude_user->end ()) {
6493
- include_user->emplace (user_name);
6494
- }
6495
- }
6496
- return false ;
6497
- }
6498
-
6499
- static void retract_excluded_users () {
6500
- for (auto user : *exclude_user) include_user->erase (user);
6501
- }
6502
-
6503
- /* *
6504
- @brief Do a logical dump of all ACL data: users, roles, grants
6505
-
6506
- @param sql_file The output SQL file to write to
6507
- @retval false success
6508
- @retval true failure
6509
- */
6510
- static bool dump_users (FILE *sql_file) {
6511
- for (auto user : *include_user) {
6512
- if (opt_add_drop_user) fprintf (sql_file, " DROP USER %s;\n " , user.c_str ());
6513
-
6514
- /* execute and dump SHOW CREATE USER */
6515
- MYSQL_RES *res;
6516
- MYSQL_ROW row;
6517
- std::string query = " SHOW CREATE USER " + user;
6518
- if (mysql_query_with_error_report (mysql, &res, query.c_str ())) return true ;
6519
- if (!res) return true ;
6520
- auto res_guard = create_scope_guard ([&] { mysql_free_result (res); });
6521
- if (nullptr == (row = mysql_fetch_row (res))) {
6522
- DB_error (mysql, " retrieving SHOW CREATE USER result" );
6523
- return true ;
6524
- }
6525
- fprintf (sql_file, " %s;\n " , row[0 ]);
6526
- }
6527
- return false ;
6528
- }
6529
-
6530
- static bool dump_grants (FILE *sql_file) {
6531
- for (auto user : *include_user) {
6532
- /* execute and dump SHOW GRANTS */
6533
- MYSQL_RES *res;
6534
- MYSQL_ROW row;
6535
- std::string query = " SHOW GRANTS FOR " + user;
6536
- if (mysql_query_with_error_report (mysql, &res, query.c_str ())) return true ;
6537
- if (!res) return true ;
6538
- auto res_guard = create_scope_guard ([&] { mysql_free_result (res); });
6539
- while (nullptr != (row = mysql_fetch_row (res))) {
6540
- fprintf (sql_file, " %s;\n " , row[0 ]);
6541
- }
6542
- if (mysql_errno (mysql) != 0 ) {
6543
- DB_error (mysql, " retrieving SHOW CREATE USER result" );
6544
- return true ;
6545
- }
6546
- }
6547
- return false ;
6548
- }
6549
-
6550
6375
/*
6551
6376
The following functions are wrappers for the dynamic string functions
6552
6377
and if they fail, the wrappers will terminate the current process.
@@ -6678,12 +6503,6 @@ int main(int argc, char **argv) {
6678
6503
*/
6679
6504
if (process_set_gtid_purged (mysql, server_has_gtid_enabled)) goto err;
6680
6505
6681
- if (opt_dump_users) {
6682
- retract_excluded_users ();
6683
- fetch_users_list_if_include_is_empty ();
6684
- dump_users (md_result_file);
6685
- }
6686
-
6687
6506
if (opt_source_data && do_show_binary_log_status (mysql)) goto err;
6688
6507
if (opt_replica_data && do_show_replica_status (mysql)) goto err;
6689
6508
if (opt_single_transaction &&
@@ -6729,8 +6548,6 @@ int main(int argc, char **argv) {
6729
6548
}
6730
6549
}
6731
6550
6732
- if (opt_dump_users) dump_grants (md_result_file);
6733
-
6734
6551
/* if --dump-replica , start the replica sql thread */
6735
6552
if (opt_replica_data && do_start_replica_sql (mysql)) goto err;
6736
6553
0 commit comments