16 #include "my_global.h"                           
   27 #include "sql_parse.h"     
   28 #include "sql_cache.h"     
   29 #include "sql_locale.h"    
   33 #include "parse_file.h"    
   36 #include "sql_table.h"     
   37 #include "sql_connect.h"   
   50 #include "item_create.h"   
   51 #include "sql_servers.h"   
   55 #include "des_key_file.h"  
   56 #include "sql_manager.h"   
   62 #include "rpl_master.h" 
   64 #include "rpl_filter.h" 
   65 #include <sql_common.h> 
   66 #include <my_stacktrace.h> 
   68 #include "mysys_err.h" 
   70 #include "sql_audit.h" 
   71 #include "probes_mysql.h" 
   72 #include "scheduler.h" 
   74 #include "sql_callback.h" 
   77 #include "global_threads.h" 
   79 #include "my_default.h" 
   81 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE 
   82 #include "../storage/perfschema/pfs_server.h" 
   87 #include "mysql_com_server.h" 
   89 #include "keycaches.h" 
   90 #include "../storage/myisam/ha_myisam.h" 
   95 #include "rpl_injector.h" 
   97 #include "rpl_handler.h" 
   99 #ifdef HAVE_SYS_PRCTL_H 
  100 #include <sys/prctl.h> 
  103 #include <thr_alarm.h> 
  104 #include <ft_global.h> 
  106 #include "sp_rcontext.h" 
  107 #include "sp_cache.h" 
  108 #include "sql_reload.h"   
  114 #ifdef HAVE_FESETROUND 
  117 #include "table_cache.h"  
  123 #define mysqld_charset &my_charset_latin1 
  127 #if defined(HAVE_DEC_3_2_THREADS) || defined(SIGNALS_DONT_BREAK_READ) || defined(HAVE_purify) && defined(__linux__) 
  128 #define HAVE_CLOSE_SERVER_SOCK 1 
  133 #include <sys/stat.h> 
  134 #ifndef __GNU_LIBRARY__ 
  135 #define __GNU_LIBRARY__       // Skip warnings in getopt.h 
  137 #include <my_getopt.h> 
  149 #if !defined(__WIN__) 
  150 #include <sys/resource.h> 
  157 #ifdef HAVE_SYS_SELECT_H 
  158 #include <sys/select.h> 
  160 #include <sys/utsname.h> 
  163 #include <my_libwrap.h> 
  165 #ifdef HAVE_SYS_MMAN_H 
  166 #include <sys/mman.h> 
  173 #ifdef HAVE_SOLARIS_LARGE_PAGES 
  174 #include <sys/mman.h> 
  175 #if defined(__sun__) && defined(__GNUC__) && defined(__cplusplus) \ 
  176     && defined(_XOPEN_SOURCE) 
  177 extern int getpagesizes(
size_t *, 
int);
 
  178 extern int getpagesizes2(
size_t *, 
int);
 
  179 extern int memcntl(caddr_t, 
size_t, 
int, caddr_t, 
int, 
int);
 
  184 int initgroups(
const char *,
unsigned int);
 
  187 #if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H) && !defined(HAVE_FEDISABLEEXCEPT) 
  189 #ifdef HAVE_FP_EXCEPT       // Fix type conflict 
  190 typedef fp_except fp_except_t;
 
  193 #ifdef HAVE_SYS_FPU_H 
  197 #ifdef HAVE_FPU_CONTROL_H 
  198 #include <fpu_control.h> 
  200 #if defined(__i386__) && !defined(HAVE_FPU_CONTROL_H) 
  201 # define fpu_control_t unsigned int 
  202 # define _FPU_EXTENDED 0x300 
  203 # define _FPU_DOUBLE 0x200 
  204 # if defined(__GNUC__) || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590) 
  205 #  define _FPU_GETCW(cw) asm volatile ("fnstcw %0" : "=m" (*&cw)) 
  206 #  define _FPU_SETCW(cw) asm volatile ("fldcw %0" : : "m" (*&cw)) 
  208 #  define _FPU_GETCW(cw) (cw= 0) 
  209 #  define _FPU_SETCW(cw) 
  213 extern "C" my_bool reopen_fstreams(
const char *filename,
 
  214                                    FILE *outstream, FILE *errstream);
 
  216 inline void setup_fpu()
 
  218 #if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H) && !defined(HAVE_FEDISABLEEXCEPT) 
  224 #if defined(FP_X_DNML) 
  225   fpsetmask(~(FP_X_INV | FP_X_DNML | FP_X_OFL | FP_X_UFL | FP_X_DZ |
 
  228   fpsetmask(~(FP_X_INV |             FP_X_OFL | FP_X_UFL | FP_X_DZ |
 
  233 #ifdef HAVE_FEDISABLEEXCEPT 
  234   fedisableexcept(FE_ALL_EXCEPT);
 
  237 #ifdef HAVE_FESETROUND 
  239   fesetround(FE_TONEAREST);
 
  248 #if defined(__i386__) && !defined(__SSE2_MATH__) 
  251   _control87(_PC_53, MCW_PC);
 
  256   cw= (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;
 
  261 #if defined(__sgi) && defined(HAVE_SYS_FPU_H) 
  264   n.fc_word = get_fpc_csr();
 
  265   n.fc_struct.flush = 0;
 
  266   set_fpc_csr(
n.fc_word);
 
  272 #define MYSQL_KILL_SIGNAL SIGTERM 
  274 #include <my_pthread.h>      
  277 extern "C" int gethostname(
char *
name, 
int namelen);
 
  280 extern "C" sig_handler handle_fatal_signal(
int sig);
 
  282 #if defined(__linux__) 
  283 #define ENABLE_TEMP_POOL 1 
  285 #define ENABLE_TEMP_POOL 0 
  290 #include <welcome_copyright_notice.h>  
  292 const char *show_comp_option_name[]= {
"YES", 
"NO", 
"DISABLED"};
 
  294 static const char *tc_heuristic_recover_names[]=
 
  296   "COMMIT", 
"ROLLBACK", NullS
 
  298 static TYPELIB tc_heuristic_recover_typelib=
 
  300   array_elements(tc_heuristic_recover_names)-1,
"",
 
  301   tc_heuristic_recover_names, NULL
 
  304 const char *first_keyword= 
"first", *binary_keyword= 
"BINARY";
 
  305 const char *my_localhost= 
"localhost", *delayed_user= 
"DELAYED";
 
  307 bool opt_large_files= 
sizeof(my_off_t) > 4;
 
  308 static my_bool opt_autocommit; 
 
  313 static my_bool opt_help= 0, opt_verbose= 0;
 
  315 arg_cmp_func Arg_comparator::comparator_matrix[5][2] =
 
  317  {&Arg_comparator::compare_real,       &Arg_comparator::compare_e_real},
 
  318  {&Arg_comparator::compare_int_signed, &Arg_comparator::compare_e_int},
 
  319  {&Arg_comparator::compare_row,        &Arg_comparator::compare_e_row},
 
  320  {&Arg_comparator::compare_decimal,    &Arg_comparator::compare_e_decimal}};
 
  324 #ifdef HAVE_PSI_INTERFACE 
  325 #if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) 
  326 static PSI_thread_key key_thread_handle_con_namedpipes;
 
  327 static PSI_cond_key key_COND_handler_count;
 
  330 #if defined(HAVE_SMEM) && !defined(EMBEDDED_LIBRARY) 
  331 static PSI_thread_key key_thread_handle_con_sharedmem;
 
  334 #if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) 
  335 static PSI_thread_key key_thread_handle_con_sockets;
 
  339 static PSI_thread_key key_thread_handle_shutdown;
 
  342 #if defined (HAVE_OPENSSL) && !defined(HAVE_YASSL) 
  343 static PSI_rwlock_key key_rwlock_openssl;
 
  348 volatile sig_atomic_t ld_assume_kernel_is_set= 0;
 
  354 #ifdef HAVE_PSI_STATEMENT_INTERFACE 
  355 PSI_statement_info stmt_info_rpl;
 
  359 static bool lower_case_table_names_used= 0;
 
  360 static bool volatile select_thread_in_use, signal_thread_in_use;
 
  362 volatile bool ready_to_exit;
 
  363 static my_bool opt_debugging= 0, opt_external_locking= 0, opt_console= 0;
 
  364 static my_bool opt_short_log_format= 0;
 
  365 static uint kill_blocked_pthreads_flag, wake_pthread;
 
  366 static ulong killed_threads;
 
  367        ulong max_used_connections;
 
  368 static char *mysqld_user, *mysqld_chroot;
 
  369 static char *default_character_set_name;
 
  370 static char *character_set_filesystem_name;
 
  371 static char *lc_messages;
 
  372 static char *lc_time_names_name;
 
  373 char *my_bind_addr_str;
 
  374 static char *default_collation_name;
 
  375 char *default_storage_engine;
 
  376 char *default_tmp_storage_engine;
 
  377 static char compiled_default_collation_name[]= MYSQL_DEFAULT_COLLATION_NAME;
 
  378 static bool binlog_format_used= 
false;
 
  382 static mysql_cond_t COND_thread_cache, COND_flush_thread_cache;
 
  386 bool opt_bin_log, opt_ignore_builtin_innodb= 0;
 
  387 my_bool opt_log, opt_slow_log, opt_log_raw;
 
  388 ulonglong log_output_options;
 
  389 my_bool opt_log_queries_not_using_indexes= 0;
 
  390 ulong opt_log_throttle_queries_not_using_indexes= 0;
 
  391 bool opt_error_log= IF_WIN(1,0);
 
  392 bool opt_disable_networking=0, opt_skip_show_db=0;
 
  393 bool opt_skip_name_resolve=0;
 
  394 my_bool opt_character_set_client_handshake= 1;
 
  395 bool server_id_supplied = 0;
 
  396 bool opt_endinfo, using_udf_functions;
 
  397 my_bool locked_in_memory;
 
  398 bool opt_using_transactions;
 
  399 bool volatile abort_loop;
 
  400 bool volatile shutdown_in_progress;
 
  402 #if defined(_WIN32) && !defined(EMBEDDED_LIBRARY) 
  403 ulong slow_start_timeout;
 
  418 bool in_bootstrap= FALSE;
 
  419 my_bool opt_bootstrap= 0;
 
  428 bool volatile grant_option;
 
  430 my_bool opt_skip_slave_start = 0; 
 
  431 my_bool opt_reckless_slave = 0;
 
  432 my_bool opt_enable_named_pipe= 0;
 
  433 my_bool opt_local_infile, opt_slave_compressed_protocol;
 
  434 my_bool opt_safe_user_create = 0;
 
  435 my_bool opt_show_slave_auth_info;
 
  436 my_bool opt_log_slave_updates= 0;
 
  437 char *opt_slave_skip_errors;
 
  438 my_bool opt_slave_allow_batching= 0;
 
  453 uint opt_server_id_bits= 0;
 
  454 ulong opt_server_id_mask= 0;
 
  455 my_bool read_only= 0, opt_readonly= 0;
 
  456 my_bool use_temp_pool, relay_log_purge;
 
  457 my_bool relay_log_recovery;
 
  458 my_bool opt_sync_frm, opt_allow_suspicious_udfs;
 
  459 my_bool opt_secure_auth= 0;
 
  460 char* opt_secure_file_priv;
 
  461 my_bool opt_log_slow_admin_statements= 0;
 
  462 my_bool opt_log_slow_slave_statements= 0;
 
  463 my_bool lower_case_file_system= 0;
 
  464 my_bool opt_large_pages= 0;
 
  465 my_bool opt_super_large_pages= 0;
 
  466 my_bool opt_myisam_use_mmap= 0;
 
  467 uint   opt_large_page_size= 0;
 
  468 #if defined(ENABLED_DEBUG_SYNC) 
  469 MYSQL_PLUGIN_IMPORT uint    opt_debug_sync_timeout= 0;
 
  471 my_bool opt_old_style_user_limits= 0, trust_function_creators= 0;
 
  477 volatile bool mqh_used = 0;
 
  478 my_bool opt_noacl= 0;
 
  479 my_bool sp_automatic_privileges= 1;
 
  481 ulong opt_binlog_rows_event_max_size;
 
  482 const char *binlog_checksum_default= 
"NONE";
 
  483 ulong binlog_checksum_options;
 
  484 my_bool opt_master_verify_checksum= 0;
 
  485 my_bool opt_slave_sql_verify_checksum= 1;
 
  486 const char *binlog_format_names[]= {
"MIXED", 
"STATEMENT", 
"ROW", NullS};
 
  487 my_bool enforce_gtid_consistency;
 
  489 const char *gtid_mode_names[]=
 
  490 {
"OFF", 
"UPGRADE_STEP_1", 
"UPGRADE_STEP_2", 
"ON", NullS};
 
  492 { array_elements(gtid_mode_names) - 1, 
"", gtid_mode_names, NULL };
 
  494 #ifdef HAVE_INITGROUPS 
  495 volatile sig_atomic_t calling_initgroups= 0; 
 
  497 uint mysqld_port, test_flags, select_errors, dropping_tables, ha_open_options;
 
  498 uint mysqld_port_timeout;
 
  499 ulong delay_key_write_options;
 
  500 uint protocol_version;
 
  501 uint lower_case_table_names;
 
  502 ulong tc_heuristic_recover= 0;
 
  503 int32 num_thread_running;
 
  504 ulong thread_created;
 
  505 ulong back_log, connect_timeout, concurrency, server_id;
 
  506 ulong table_cache_size, table_def_size;
 
  507 ulong table_cache_instances;
 
  508 ulong table_cache_size_per_instance;
 
  510 ulong slow_launch_time;
 
  511 int32 slave_open_temp_tables;
 
  512 ulong open_files_limit, max_binlog_size, max_relay_log_size;
 
  513 ulong slave_trans_retries;
 
  514 uint  slave_net_timeout;
 
  515 ulong slave_exec_mode_options;
 
  516 ulonglong slave_type_conversions_options;
 
  517 ulong opt_mts_slave_parallel_workers;
 
  518 ulonglong opt_mts_pending_jobs_size_max;
 
  519 ulonglong slave_rows_search_algorithms_options;
 
  521 uint slave_rows_last_search_algorithm_used;
 
  523 ulong binlog_cache_size=0;
 
  524 ulonglong  max_binlog_cache_size=0;
 
  525 ulong slave_max_allowed_packet= 0;
 
  526 ulong binlog_stmt_cache_size=0;
 
  528 int32 opt_binlog_max_flush_queue_time= 0;
 
  529 ulonglong  max_binlog_stmt_cache_size=0;
 
  530 ulong query_cache_size=0;
 
  531 ulong refresh_version;  
 
  532 query_id_t global_query_id;
 
  536 ulong aborted_threads, aborted_connects;
 
  537 ulong delayed_insert_timeout, delayed_insert_limit, delayed_queue_size;
 
  538 ulong delayed_insert_threads, delayed_insert_writes, delayed_rows_in_use;
 
  539 ulong delayed_insert_errors,flush_time;
 
  541 ulong binlog_cache_use= 0, binlog_cache_disk_use= 0;
 
  542 ulong binlog_stmt_cache_use= 0, binlog_stmt_cache_disk_use= 0;
 
  543 ulong max_connections, max_connect_errors;
 
  544 ulong rpl_stop_slave_timeout= LONG_TIMEOUT;
 
  545 my_bool log_bin_use_v1_row_events= 0;
 
  546 bool thread_cache_size_specified= 
false;
 
  547 bool host_cache_size_specified= 
false;
 
  548 bool table_definition_cache_specified= 
false;
 
  550 Error_log_throttle err_log_throttle(Log_throttle::LOG_THROTTLE_WINDOW_SIZE,
 
  552                                     "Error log throttle: %10lu 'Can't create" 
  553                                     " thread to handle new connection'" 
  554                                     " error(s) suppressed");
 
  560 ulong max_prepared_stmt_count;
 
  571 ulong prepared_stmt_count=0;
 
  572 ulong thread_id=1L,current_pid;
 
  573 ulong slow_launch_threads = 0;
 
  574 uint sync_binlog_period= 0, sync_relaylog_period= 0,
 
  575      sync_relayloginfo_period= 0, sync_masterinfo_period= 0,
 
  576      opt_mts_checkpoint_period, opt_mts_checkpoint_group;
 
  577 ulong expire_logs_days = 0;
 
  582 ulong stored_program_cache_size= 0;
 
  584 const double log_10[] = {
 
  585   1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009,
 
  586   1e010, 1e011, 1e012, 1e013, 1e014, 1e015, 1e016, 1e017, 1e018, 1e019,
 
  587   1e020, 1e021, 1e022, 1e023, 1e024, 1e025, 1e026, 1e027, 1e028, 1e029,
 
  588   1e030, 1e031, 1e032, 1e033, 1e034, 1e035, 1e036, 1e037, 1e038, 1e039,
 
  589   1e040, 1e041, 1e042, 1e043, 1e044, 1e045, 1e046, 1e047, 1e048, 1e049,
 
  590   1e050, 1e051, 1e052, 1e053, 1e054, 1e055, 1e056, 1e057, 1e058, 1e059,
 
  591   1e060, 1e061, 1e062, 1e063, 1e064, 1e065, 1e066, 1e067, 1e068, 1e069,
 
  592   1e070, 1e071, 1e072, 1e073, 1e074, 1e075, 1e076, 1e077, 1e078, 1e079,
 
  593   1e080, 1e081, 1e082, 1e083, 1e084, 1e085, 1e086, 1e087, 1e088, 1e089,
 
  594   1e090, 1e091, 1e092, 1e093, 1e094, 1e095, 1e096, 1e097, 1e098, 1e099,
 
  595   1e100, 1e101, 1e102, 1e103, 1e104, 1e105, 1e106, 1e107, 1e108, 1e109,
 
  596   1e110, 1e111, 1e112, 1e113, 1e114, 1e115, 1e116, 1e117, 1e118, 1e119,
 
  597   1e120, 1e121, 1e122, 1e123, 1e124, 1e125, 1e126, 1e127, 1e128, 1e129,
 
  598   1e130, 1e131, 1e132, 1e133, 1e134, 1e135, 1e136, 1e137, 1e138, 1e139,
 
  599   1e140, 1e141, 1e142, 1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149,
 
  600   1e150, 1e151, 1e152, 1e153, 1e154, 1e155, 1e156, 1e157, 1e158, 1e159,
 
  601   1e160, 1e161, 1e162, 1e163, 1e164, 1e165, 1e166, 1e167, 1e168, 1e169,
 
  602   1e170, 1e171, 1e172, 1e173, 1e174, 1e175, 1e176, 1e177, 1e178, 1e179,
 
  603   1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186, 1e187, 1e188, 1e189,
 
  604   1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196, 1e197, 1e198, 1e199,
 
  605   1e200, 1e201, 1e202, 1e203, 1e204, 1e205, 1e206, 1e207, 1e208, 1e209,
 
  606   1e210, 1e211, 1e212, 1e213, 1e214, 1e215, 1e216, 1e217, 1e218, 1e219,
 
  607   1e220, 1e221, 1e222, 1e223, 1e224, 1e225, 1e226, 1e227, 1e228, 1e229,
 
  608   1e230, 1e231, 1e232, 1e233, 1e234, 1e235, 1e236, 1e237, 1e238, 1e239,
 
  609   1e240, 1e241, 1e242, 1e243, 1e244, 1e245, 1e246, 1e247, 1e248, 1e249,
 
  610   1e250, 1e251, 1e252, 1e253, 1e254, 1e255, 1e256, 1e257, 1e258, 1e259,
 
  611   1e260, 1e261, 1e262, 1e263, 1e264, 1e265, 1e266, 1e267, 1e268, 1e269,
 
  612   1e270, 1e271, 1e272, 1e273, 1e274, 1e275, 1e276, 1e277, 1e278, 1e279,
 
  613   1e280, 1e281, 1e282, 1e283, 1e284, 1e285, 1e286, 1e287, 1e288, 1e289,
 
  614   1e290, 1e291, 1e292, 1e293, 1e294, 1e295, 1e296, 1e297, 1e298, 1e299,
 
  615   1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307, 1e308
 
  618 time_t server_start_time, flush_status_time;
 
  620 char server_uuid[UUID_LENGTH+1];
 
  621 const char *server_uuid_ptr;
 
  622 char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30];
 
  623 char default_logfile_name[FN_REFLEN];
 
  624 char *default_tz_name;
 
  625 char log_error_file[FN_REFLEN], glob_hostname[FN_REFLEN];
 
  626 char mysql_real_data_home[FN_REFLEN],
 
  627      lc_messages_dir[FN_REFLEN], reg_ext[FN_EXTLEN],
 
  628      mysql_charsets_dir[FN_REFLEN],
 
  629      *opt_init_file, *opt_tc_log_file;
 
  630 char *lc_messages_dir_ptr, *log_error_file_ptr;
 
  631 char mysql_unpacked_real_data_home[FN_REFLEN];
 
  632 int mysql_unpacked_real_data_home_len;
 
  633 uint mysql_real_data_home_len, mysql_data_home_len= 1;
 
  635 const key_map key_map_empty(0);
 
  637 char logname_path[FN_REFLEN];
 
  638 char slow_logname_path[FN_REFLEN];
 
  639 char secure_file_real_path[FN_REFLEN];
 
  641 DATE_TIME_FORMAT global_date_format, global_datetime_format, global_time_format;
 
  644 char *mysql_data_home= 
const_cast<char*
>(
".");
 
  645 const char *mysql_real_data_home_ptr= mysql_real_data_home;
 
  646 char server_version[SERVER_VERSION_LENGTH];
 
  647 char *mysqld_unix_port, *opt_mysql_tmpdir;
 
  648 ulong thread_handling;
 
  651 const char *in_left_expr_name= 
"<left expr>";
 
  653 const char *in_additional_cond= 
"<IN COND>";
 
  654 const char *in_having_cond= 
"<IN HAVING>";
 
  658 ulong connection_errors_select= 0;
 
  660 ulong connection_errors_accept= 0;
 
  662 ulong connection_errors_tcpwrap= 0;
 
  664 ulong connection_errors_internal= 0;
 
  666 ulong connection_errors_max_connection= 0;
 
  668 ulong connection_errors_peer_addr= 0;
 
  691 CHARSET_INFO *system_charset_info, *files_charset_info ;
 
  692 CHARSET_INFO *national_charset_info, *table_alias_charset;
 
  699 SHOW_COMP_OPTION have_ssl, have_symlink, have_dlopen, have_query_cache;
 
  700 SHOW_COMP_OPTION have_geometry, have_rtree_keys;
 
  701 SHOW_COMP_OPTION have_crypt, have_compress;
 
  702 SHOW_COMP_OPTION have_profiling;
 
  711   LOCK_status, LOCK_error_log, LOCK_uuid_generator,
 
  712   LOCK_delayed_insert, LOCK_delayed_status, LOCK_delayed_create,
 
  714   LOCK_global_system_variables,
 
  715   LOCK_user_conn, LOCK_slave_list, LOCK_active_mi,
 
  716   LOCK_connection_count, LOCK_error_messages;
 
  740 mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
 
  743 pthread_t signal_thread;
 
  744 pthread_attr_t connection_attrib;
 
  748 int mysqld_server_started= 0;
 
  754 ulong master_retry_count=0;
 
  755 char *master_info_file;
 
  756 char *relay_log_info_file, *report_user, *report_password, *report_host;
 
  757 char *opt_relay_logname = 0, *opt_relaylog_index_name=0;
 
  758 char *opt_logname, *opt_slow_logname, *opt_bin_logname;
 
  762 static volatile sig_atomic_t kill_in_progress;
 
  765 static my_bool opt_myisam_log;
 
  766 static int cleanup_done;
 
  767 static ulong opt_specialflag;
 
  768 static char *opt_update_logname;
 
  769 char *opt_binlog_index_name;
 
  770 char *mysql_home_ptr, *pidfile_name_ptr;
 
  772 static int defaults_argc;
 
  781 static char **defaults_argv;
 
  783 static int remaining_argc;
 
  785 static char **remaining_argv;
 
  790 #if defined(HAVE_OPENSSL) && !defined(HAVE_YASSL) 
  791 bool init_rsa_keys(
void);
 
  792 void deinit_rsa_keys(
void);
 
  793 int show_rsa_public_key(THD *thd, 
SHOW_VAR *var, 
char *buff);
 
  796 static volatile sig_atomic_t global_thread_count= 0;
 
  797 static std::set<THD*> *global_thread_list= NULL;
 
  799 ulong max_blocked_pthreads= 0;
 
  800 static ulong blocked_pthread_count= 0;
 
  801 static std::list<THD*> *waiting_thd_list= NULL;
 
  810 static void delete_global_thread_list()
 
  812   delete global_thread_list;
 
  813   delete waiting_thd_list;
 
  814   global_thread_list= NULL;
 
  815   waiting_thd_list= NULL;
 
  818 Thread_iterator global_thread_list_begin()
 
  821   return global_thread_list->begin();
 
  824 Thread_iterator global_thread_list_end()
 
  827   return global_thread_list->end();
 
  830 void add_global_thread(THD *thd)
 
  832   DBUG_PRINT(
"info", (
"add_global_thread %p", thd));
 
  834   const bool have_thread=
 
  835     global_thread_list->find(thd) != global_thread_list->end();
 
  838     ++global_thread_count;
 
  839     global_thread_list->insert(thd);
 
  842   DBUG_ASSERT(!have_thread);
 
  845 void remove_global_thread(THD *thd)
 
  847   DBUG_PRINT(
"info", (
"remove_global_thread %p current_linfo %p",
 
  848                       thd, thd->current_linfo));
 
  850   DBUG_ASSERT(thd->release_resources_done());
 
  852   const size_t num_erased= global_thread_list->erase(thd);
 
  854     --global_thread_count;
 
  856   DBUG_ASSERT(1 == num_erased);
 
  861 uint get_thread_count()
 
  863   return (uint) global_thread_count;
 
  867 void set_remaining_args(
int argc, 
char **argv)
 
  869   remaining_argc= argc;
 
  870   remaining_argv= argv;
 
  878 ulong sql_rnd_with_mutex()
 
  881   ulong tmp=(ulong) (my_rnd(&sql_rand) * 0xffffffff); 
 
  886 #ifdef HAVE_PSI_STATEMENT_INTERFACE 
  887 PSI_statement_info stmt_info_new_packet;
 
  890 #ifndef EMBEDDED_LIBRARY 
  891 void net_before_header_psi(
struct st_net *net, 
void *user_data, 
size_t )
 
  894   thd= 
static_cast<THD*
> (user_data);
 
  895   DBUG_ASSERT(thd != NULL);
 
  897   if (thd->m_server_idle)
 
  906     MYSQL_SOCKET_SET_STATE(net->vio->mysql_socket, PSI_SOCKET_STATE_IDLE);
 
  911 void net_after_header_psi(
struct st_net *net, 
void *user_data, 
size_t , my_bool rc)
 
  914   thd= 
static_cast<THD*
> (user_data);
 
  915   DBUG_ASSERT(thd != NULL);
 
  917   if (thd->m_server_idle)
 
  934       thd->m_statement_psi= MYSQL_START_STATEMENT(&thd->m_statement_state,
 
  935                                                   stmt_info_new_packet.m_key,
 
  936                                                   thd->db, thd->db_length,
 
  939       THD_STAGE_INFO(thd, stage_init);
 
  946     MYSQL_SOCKET_SET_STATE(net->vio->mysql_socket, PSI_SOCKET_STATE_ACTIVE);
 
  950 void init_net_server_extension(THD *thd)
 
  952 #ifdef HAVE_PSI_INTERFACE 
  954   thd->m_idle_psi= NULL;
 
  955   thd->m_statement_psi= NULL;
 
  956   thd->m_server_idle= 
false;
 
  958   thd->m_net_server_extension.m_user_data= thd;
 
  959   thd->m_net_server_extension.m_before_header= net_before_header_psi;
 
  960   thd->m_net_server_extension.m_after_header= net_after_header_psi;
 
  962   thd->net.extension= & thd->m_net_server_extension;
 
  964   thd->net.extension= NULL;
 
  986   enum loglevel m_level;
 
  997   : m_level(level), m_message()
 
  999   m_message.copy(message, strlen(message), &my_charset_latin1);
 
 1015     sql_print_error(
"Buffered error: %s\n", m_message.c_ptr_safe());
 
 1018     sql_print_warning(
"Buffered warning: %s\n", m_message.c_ptr_safe());
 
 1020   case INFORMATION_LEVEL:
 
 1049   void buffer(
enum loglevel m_level, 
const char *
msg);
 
 1063 void Buffered_logs::init()
 
 1065   init_alloc_root(&m_root, 1024, 0);
 
 1068 void Buffered_logs::cleanup()
 
 1070   m_list.delete_elements();
 
 1071   free_root(&m_root, MYF(0));
 
 1087     m_list.push_back(log, &m_root);
 
 1110 static void buffered_option_error_reporter(
enum loglevel 
level,
 
 1111                                            const char *format, ...)
 
 1116   va_start(args, format);
 
 1117   my_vsnprintf(buffer, 
sizeof(buffer), format, args);
 
 1119   buffered_logs.
buffer(level, buffer);
 
 1139 static void charset_error_reporter(
enum loglevel level,
 
 1140                                    const char *format, ...)
 
 1143   va_start(args, format);
 
 1152 #ifndef EMBEDDED_LIBRARY 
 1153 struct passwd *user_info;
 
 1154 static pthread_t select_thread;
 
 1155 static uint thr_kill_signal;
 
 1162 #include <process.h> 
 1165 static uint handler_count;
 
 1166 static bool start_mode=0, use_opt_args;
 
 1167 static int opt_argc;
 
 1168 static char **opt_argv;
 
 1170 #if !defined(EMBEDDED_LIBRARY) 
 1171 static HANDLE hEventShutdown;
 
 1172 static char shutdown_event_name[40];
 
 1179 static char pipe_name[512];
 
 1180 static SECURITY_ATTRIBUTES saPipeSecurity;
 
 1181 static SECURITY_DESCRIPTOR sdPipeDescriptor;
 
 1182 static HANDLE hPipe = INVALID_HANDLE_VALUE;
 
 1185 #ifndef EMBEDDED_LIBRARY 
 1186 bool mysqld_embedded=0;
 
 1188 bool mysqld_embedded=1;
 
 1191 static my_bool plugins_are_initialized= FALSE;
 
 1194 static const char* default_dbug_option;
 
 1197 const char *libwrapName= NULL;
 
 1199 int deny_severity = LOG_WARNING;
 
 1201 #ifdef HAVE_QUERY_CACHE 
 1202 ulong query_cache_min_res_unit= QUERY_CACHE_MIN_RESULT_DATA_SIZE;
 
 1206 char *shared_memory_base_name= default_shared_memory_base_name;
 
 1207 my_bool opt_enable_shared_memory;
 
 1208 HANDLE smem_event_connect_request= 0;
 
 1211 my_bool opt_use_ssl  = 0;
 
 1212 char *opt_ssl_ca= NULL, *opt_ssl_capath= NULL, *opt_ssl_cert= NULL,
 
 1213      *opt_ssl_cipher= NULL, *opt_ssl_key= NULL, *opt_ssl_crl= NULL,
 
 1214      *opt_ssl_crlpath= NULL;
 
 1217 #include <openssl/crypto.h> 
 1219 typedef struct CRYPTO_dynlock_value
 
 1224 static openssl_lock_t *openssl_stdlocks;
 
 1225 static openssl_lock_t *openssl_dynlock_create(
const char *, 
int);
 
 1226 static void openssl_dynlock_destroy(openssl_lock_t *, 
const char *, 
int);
 
 1227 static void openssl_lock_function(
int, 
int, 
const char *, 
int);
 
 1228 static void openssl_lock(
int, openssl_lock_t *, 
const char *, 
int);
 
 1229 static unsigned long openssl_id_function();
 
 1232 #ifndef EMBEDDED_LIBRARY 
 1233 struct st_VioSSLFd *ssl_acceptor_fd;
 
 1241 uint connection_count= 0;
 
 1245 pthread_handler_t signal_hand(
void *arg);
 
 1246 static int mysql_init_variables(
void);
 
 1247 static int get_options(
int *argc_ptr, 
char ***argv_ptr);
 
 1248 static void add_terminator(vector<my_option> *options);
 
 1249 extern "C" my_bool mysqld_get_one_option(
int, 
const struct my_option *, 
char *);
 
 1250 static void set_server_version(
void);
 
 1251 static int init_thread_environment();
 
 1252 static char *get_relative_path(
const char *path);
 
 1253 static int fix_paths(
void);
 
 1254 void handle_connections_sockets();
 
 1256 pthread_handler_t handle_connections_sockets_thread(
void *arg);
 
 1258 pthread_handler_t kill_server_thread(
void *arg);
 
 1260 static bool read_init_file(
char *file_name);
 
 1262 pthread_handler_t handle_connections_namedpipes(
void *arg);
 
 1265 pthread_handler_t handle_connections_shared_memory(
void *arg);
 
 1267 pthread_handler_t handle_slave(
void *arg);
 
 1268 static void clean_up(
bool print_message);
 
 1269 static int test_if_case_insensitive(
const char *dir_name);
 
 1271 #ifndef EMBEDDED_LIBRARY 
 1272 static bool pid_file_created= 
false;
 
 1273 static void usage(
void);
 
 1274 static void start_signal_handler(
void);
 
 1275 static void close_server_sock();
 
 1276 static void clean_up_mutexes(
void);
 
 1277 static void wait_for_signal_thread_to_end(
void);
 
 1278 static void create_pid_file();
 
 1279 static void mysqld_exit(
int exit_code) __attribute__((noreturn));
 
 1281 static void delete_pid_file(myf 
flags);
 
 1282 static void end_ssl();
 
 1285 #ifndef EMBEDDED_LIBRARY 
 1290 static void close_connections(
void)
 
 1295   DBUG_ENTER(
"close_connections");
 
 1298   kill_blocked_pthreads_flag++;
 
 1299   kill_blocked_pthreads();
 
 1300   uint dump_thread_count= 0;
 
 1301   uint dump_thread_kill_retries= 8;
 
 1303 #if !defined(__WIN__) 
 1304   DBUG_PRINT(
"quit", (
"waiting for select thread: 0x%lx",
 
 1305                       (ulong) select_thread));
 
 1308   while (select_thread_in_use)
 
 1313     DBUG_PRINT(
"info",(
"Waiting for select thread"));
 
 1315 #ifndef DONT_USE_THR_ALARM 
 1316     if (pthread_kill(select_thread, thr_client_alarm))
 
 1319     set_timespec(abstime, 2);
 
 1320     for (uint tmp=0 ; tmp < 10 && select_thread_in_use; tmp++)
 
 1328     if (error != 0 && !count++)
 
 1329       sql_print_error(
"Got error %d from mysql_cond_timedwait", error);
 
 1331     close_server_sock();
 
 1338   DBUG_PRINT(
"quit",(
"Closing sockets"));
 
 1339   if (!opt_disable_networking )
 
 1341     if (mysql_socket_getfd(ip_sock) != INVALID_SOCKET)
 
 1349   if (hPipe != INVALID_HANDLE_VALUE && opt_enable_named_pipe)
 
 1352     DBUG_PRINT(
"quit", (
"Closing named pipes") );
 
 1355     if ((temp = CreateFile(pipe_name,
 
 1356          GENERIC_READ | GENERIC_WRITE,
 
 1361          NULL )) != INVALID_HANDLE_VALUE)
 
 1363       WaitNamedPipe(pipe_name, 1000);
 
 1364       DWORD dwMode = PIPE_READMODE_BYTE | PIPE_WAIT;
 
 1365       SetNamedPipeHandleState(temp, &dwMode, NULL, NULL);
 
 1367       DisconnectNamedPipe(temp);
 
 1372 #ifdef HAVE_SYS_UN_H 
 1373   if (mysql_socket_getfd(unix_sock) != INVALID_SOCKET)
 
 1377     (void) unlink(mysqld_unix_port);
 
 1389   sql_print_information(
"Giving %d client threads a chance to die gracefully",
 
 1390                         static_cast<int>(get_thread_count()));
 
 1394   Thread_iterator it= global_thread_list->begin();
 
 1395   for (; it != global_thread_list->end(); ++it)
 
 1398     DBUG_PRINT(
"quit",(
"Informing thread %ld that it's time to die",
 
 1401     if (tmp->slave_thread)
 
 1403     if (tmp->get_command() == COM_BINLOG_DUMP ||
 
 1404         tmp->get_command() == COM_BINLOG_DUMP_GTID)
 
 1406       ++dump_thread_count;
 
 1409     tmp->killed= THD::KILL_CONNECTION;
 
 1410     DBUG_EXECUTE_IF(
"Check_dump_thread_is_alive",
 
 1412                       DBUG_ASSERT(tmp->get_command() != COM_BINLOG_DUMP &&
 
 1413                                   tmp->get_command() != COM_BINLOG_DUMP_GTID);
 
 1415     MYSQL_CALLBACK(thread_scheduler, post_kill_notification, (tmp));
 
 1419       tmp->mysys_var->abort=1;
 
 1421       if (tmp->mysys_var->current_cond)
 
 1435   sql_print_information(
"Shutting down slave threads");
 
 1438   if (dump_thread_count)
 
 1444     while (get_thread_count() > dump_thread_count && dump_thread_kill_retries)
 
 1447       dump_thread_kill_retries--;
 
 1450     for (it= global_thread_list->begin(); it != global_thread_list->end(); ++it)
 
 1453       DBUG_PRINT(
"quit",(
"Informing dump thread %ld that it's time to die",
 
 1455       if (tmp->get_command() == COM_BINLOG_DUMP ||
 
 1456           tmp->get_command() == COM_BINLOG_DUMP_GTID)
 
 1458         tmp->killed= THD::KILL_CONNECTION;
 
 1459         MYSQL_CALLBACK(thread_scheduler, post_kill_notification, (tmp));
 
 1463           tmp->mysys_var->abort= 1;
 
 1465           if (tmp->mysys_var->current_cond)
 
 1478   if (get_thread_count() > 0)
 
 1487   sql_print_information(
"Forcefully disconnecting %d remaining clients",
 
 1488                         static_cast<int>(get_thread_count()));
 
 1490 #ifndef __bsdi__ // Bug in BSDI kernel 
 1491   DBUG_PRINT(
"quit", (
"Locking LOCK_thread_count"));
 
 1493   for (it= global_thread_list->begin(); it != global_thread_list->end(); ++it)
 
 1499         sql_print_warning(ER_DEFAULT(ER_FORCING_CLOSE),my_progname,
 
 1501                           (tmp->main_security_ctx.user ?
 
 1502                            tmp->main_security_ctx.user : 
""));
 
 1503       close_connection(tmp);
 
 1506   DBUG_PRINT(
"quit",(
"Unlocking LOCK_thread_count"));
 
 1508 #endif // Bug in BSDI kernel 
 1511   DBUG_PRINT(
"quit",(
"Waiting for threads to die (count=%u)",
 
 1512                      get_thread_count()));
 
 1514   while (get_thread_count() > 0)
 
 1517     DBUG_PRINT(
"quit", (
"One thread died (count=%u)", get_thread_count()));
 
 1522   DBUG_PRINT(
"quit",(
"close_connections thread"));
 
 1527 static void close_server_sock()
 
 1529 #ifdef HAVE_CLOSE_SERVER_SOCK 
 1530   DBUG_ENTER(
"close_server_sock");
 
 1533   if (mysql_socket_getfd(tmp_sock) != INVALID_SOCKET)
 
 1536     DBUG_PRINT(
"info",(
"calling shutdown on TCP/IP socket"));
 
 1540   if (mysql_socket_getfd(tmp_sock) != INVALID_SOCKET)
 
 1543     DBUG_PRINT(
"info",(
"calling shutdown on unix socket"));
 
 1545     (void) unlink(mysqld_unix_port);
 
 1554 void kill_mysql(
void)
 
 1556   DBUG_ENTER(
"kill_mysql");
 
 1558 #if defined(SIGNALS_DONT_BREAK_READ) && !defined(EMBEDDED_LIBRARY) 
 1560   close_server_sock();        
 
 1563 #if defined(__WIN__) 
 1564 #if !defined(EMBEDDED_LIBRARY) 
 1566     if (!SetEvent(hEventShutdown))
 
 1568       DBUG_PRINT(
"error",(
"Got error: %ld from SetEvent",GetLastError()));
 
 1578 #elif defined(HAVE_PTHREAD_KILL) 
 1579   if (pthread_kill(signal_thread, MYSQL_KILL_SIGNAL))
 
 1581     DBUG_PRINT(
"error",(
"Got error %d from pthread_kill",errno)); 
 
 1583 #elif !defined(SIGNALS_DONT_BREAK_READ) 
 1584   kill(current_pid, MYSQL_KILL_SIGNAL);
 
 1586   DBUG_PRINT(
"quit",(
"After pthread_kill"));
 
 1587   shutdown_in_progress=1;     
 
 1588 #ifdef SIGNALS_DONT_BREAK_READ 
 1589   if (!kill_in_progress)
 
 1595                                     &tmp, &connection_attrib,
 
 1596                                     kill_server_thread, (
void*) 0)))
 
 1597       sql_print_error(
"Can't create thread to kill server (errno= %d).", error);
 
 1614 #if !defined(__WIN__) 
 1615 static void *kill_server(
void *sig_ptr)
 
 1616 #define RETURN_FROM_KILL_SERVER return 0 
 1618 static void __cdecl kill_server(
int sig_ptr)
 
 1619 #define RETURN_FROM_KILL_SERVER return 
 1622   DBUG_ENTER(
"kill_server");
 
 1623 #ifndef EMBEDDED_LIBRARY 
 1624   int sig=(int) (
long) sig_ptr;     
 
 1626   if (kill_in_progress)       
 
 1629     RETURN_FROM_KILL_SERVER;
 
 1631   kill_in_progress=TRUE;
 
 1634     my_sigset(sig, SIG_IGN);                    
 
 1635   if (sig == MYSQL_KILL_SIGNAL || sig == 0)
 
 1636     sql_print_information(ER_DEFAULT(ER_NORMAL_SHUTDOWN),my_progname);
 
 1638     sql_print_error(ER_DEFAULT(ER_GOT_SIGNAL),my_progname,sig); 
 
 1640 #if defined(HAVE_SMEM) && defined(__WIN__) 
 1644   if (opt_enable_shared_memory)
 
 1646     if (!SetEvent(smem_event_connect_request))
 
 1649                  (
"Got error: %ld from SetEvent of smem_event_connect_request",
 
 1655   close_connections();
 
 1656   if (sig != MYSQL_KILL_SIGNAL &&
 
 1668   RETURN_FROM_KILL_SERVER;                      
 
 1673   RETURN_FROM_KILL_SERVER;
 
 1679 #if defined(USE_ONE_SIGNAL_HAND) 
 1680 pthread_handler_t kill_server_thread(
void *arg __attribute__((unused)))
 
 1693 extern "C" sig_handler print_signal_warning(
int sig)
 
 1696     sql_print_warning(
"Got signal %d from thread %ld", sig,my_thread_id());
 
 1697 #ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY 
 1698   my_sigset(sig,print_signal_warning);    
 
 1700 #if !defined(__WIN__) 
 1706 #ifndef EMBEDDED_LIBRARY 
 1708 static void init_error_log_mutex()
 
 1714 static void clean_up_error_log_mutex()
 
 1730 void unireg_end(
void)
 
 1734 #if defined(SIGNALS_DONT_BREAK_READ) 
 1742 extern "C" void unireg_abort(
int exit_code)
 
 1744   DBUG_ENTER(
"unireg_abort");
 
 1749     sql_print_error(
"Aborting\n");
 
 1750   clean_up(!opt_help && (exit_code || !opt_bootstrap)); 
 
 1751   DBUG_PRINT(
"quit",(
"done with cleanup in unireg_abort"));
 
 1752   mysqld_exit(exit_code);
 
 1755 static void mysqld_exit(
int exit_code)
 
 1762   wait_for_signal_thread_to_end();
 
 1763   mysql_audit_finalize();
 
 1765   clean_up_error_log_mutex();
 
 1766 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE 
 1769   my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
 
 1779 void gtid_server_cleanup()
 
 1782   delete global_sid_map;
 
 1783   delete global_sid_lock;
 
 1784   global_sid_lock= NULL;
 
 1785   global_sid_map= NULL;
 
 1795 bool gtid_server_init()
 
 1799      !(global_sid_map= 
new Sid_map(global_sid_lock)) ||
 
 1800      !(gtid_state= 
new Gtid_state(global_sid_lock, global_sid_map)));
 
 1803     gtid_server_cleanup();
 
 1809 void clean_up(
bool print_message)
 
 1811   DBUG_PRINT(
"exit",(
"clean_up"));
 
 1815   stop_handle_manager();
 
 1818   memcached_shutdown();
 
 1824   if ((opt_help == 0) || (opt_verbose > 0))
 
 1825     sql_print_information(
"Binlog end");
 
 1826   ha_binlog_end(current_thd);
 
 1828   logger.cleanup_base();
 
 1830   injector::free_instance();
 
 1831   mysql_bin_log.cleanup();
 
 1832   gtid_server_cleanup();
 
 1834 #ifdef HAVE_REPLICATION 
 1836     bitmap_free(&slave_error_mask);
 
 1839   my_dboptions_cache_free();
 
 1840   ignore_db_dirs_free();
 
 1841 #ifndef NO_EMBEDDED_ACCESS_CHECKS 
 1846   query_cache_destroy();
 
 1847   hostname_cache_free();
 
 1848   item_user_lock_free();
 
 1850   item_create_cleanup();
 
 1862   delegates_destroy();
 
 1866   key_caches.delete_elements((
void (*)(
const char*, uchar*)) free_key_cache);
 
 1867   multi_keycache_free();
 
 1870   my_free_open_file_info();
 
 1872     free_defaults(defaults_argv);
 
 1873   free_tmpdir(&mysql_tmpdir_list);
 
 1874   my_free(opt_bin_logname);
 
 1875   bitmap_free(&temp_pool);
 
 1876   free_max_user_conn();
 
 1877 #ifdef HAVE_REPLICATION 
 1880   delete binlog_filter;
 
 1885 #if defined(ENABLED_DEBUG_SYNC) 
 1890   delete_pid_file(MYF(0));
 
 1892   if (print_message && my_default_lc_messages && server_start_time)
 
 1893     sql_print_information(ER_DEFAULT(ER_SHUTDOWN_COMPLETE),my_progname);
 
 1895   MYSQL_CALLBACK(thread_scheduler, end, ());
 
 1897   finish_client_errs();
 
 1898   (void) my_error_unregister(ER_ERROR_FIRST, ER_ERROR_LAST); 
 
 1899   DBUG_PRINT(
"quit", (
"Error messages freed"));
 
 1901   logger.cleanup_end();
 
 1902   my_atomic_rwlock_destroy(&opt_binlog_max_flush_queue_time_lock);
 
 1903   my_atomic_rwlock_destroy(&global_query_id_lock);
 
 1904   my_atomic_rwlock_destroy(&thread_running_lock);
 
 1907   DBUG_PRINT(
"quit", (
"got thread count lock"));
 
 1913   delete_global_thread_list();
 
 1915   my_free(const_cast<char*>(log_bin_basename));
 
 1916   my_free(const_cast<char*>(log_bin_index));
 
 1917 #ifndef EMBEDDED_LIBRARY 
 1918   my_free(const_cast<char*>(relay_log_basename));
 
 1919   my_free(const_cast<char*>(relay_log_index));
 
 1921   free_list(opt_plugin_load_list_ptr);
 
 1924     (void) pthread_key_delete(THR_THD);
 
 1927     (void) pthread_key_delete(THR_MALLOC);
 
 1933   DBUG_PRINT(
"quit", (
"done with cleanup"));
 
 1937 #ifndef EMBEDDED_LIBRARY 
 1943 static void wait_for_signal_thread_to_end()
 
 1950   for (i= 0 ; i < 100 && signal_thread_in_use; i++)
 
 1952     if (pthread_kill(signal_thread, MYSQL_KILL_SIGNAL) != ESRCH)
 
 1959 static void clean_up_mutexes()
 
 1976   for (
int i= 0; i < CRYPTO_num_locks(); ++
i)
 
 1978   OPENSSL_free(openssl_stdlocks);
 
 2013 const char *MY_BIND_ALL_ADDRESSES= 
"*";
 
 2016 #ifndef EMBEDDED_LIBRARY 
 2017 static void set_ports()
 
 2020   if (!mysqld_port && !opt_disable_networking)
 
 2022     mysqld_port= MYSQL_PORT;
 
 2034 #if MYSQL_PORT_DEFAULT == 0 
 2035     struct  servent *serv_ptr;
 
 2036     if ((serv_ptr= getservbyname(
"mysql", 
"tcp")))
 
 2037       mysqld_port= ntohs((u_short) serv_ptr->s_port); 
 
 2039     if ((env = getenv(
"MYSQL_TCP_PORT")))
 
 2040       mysqld_port= (uint) atoi(env);    
 
 2042   if (!mysqld_unix_port)
 
 2045     mysqld_unix_port= (
char*) MYSQL_NAMEDPIPE;
 
 2047     mysqld_unix_port= (
char*) MYSQL_UNIX_ADDR;
 
 2049     if ((env = getenv(
"MYSQL_UNIX_PORT")))
 
 2050       mysqld_unix_port= env;      
 
 2056 static struct passwd *check_user(
const char *user)
 
 2058 #if !defined(__WIN__) 
 2059   struct passwd *tmp_user_info;
 
 2060   uid_t user_id= geteuid();
 
 2069       tmp_user_info= getpwnam(user);
 
 2070       if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
 
 2073                     "One can only use the --user switch if running as root\n");
 
 2082       sql_print_error(
"Fatal error: Please read \"Security\" section of the manual to find out how to run mysqld as root!\n");
 
 2088   if (!strcmp(user,
"root"))
 
 2091   if (!(tmp_user_info= getpwnam(user)))
 
 2095     for (pos= user; my_isdigit(mysqld_charset,*pos); pos++) ;
 
 2098     if (!(tmp_user_info= getpwuid(atoi(user))))
 
 2101   return tmp_user_info;
 
 2105   sql_print_error(
"Fatal error: Can't change to run as user '%s' ;  Please check that the user exists!\n",user);
 
 2108 #ifdef PR_SET_DUMPABLE 
 2109   if (test_flags & TEST_CORE_ON_SIGNAL)
 
 2112     (void) prctl(PR_SET_DUMPABLE, 1);
 
 2120 static void set_user(
const char *user, 
struct passwd *user_info_arg)
 
 2123 #if !defined(__WIN__) 
 2124   DBUG_ASSERT(user_info_arg != 0);
 
 2125 #ifdef HAVE_INITGROUPS 
 2132   calling_initgroups= 1;
 
 2133   initgroups((
char*) user, user_info_arg->pw_gid);
 
 2134   calling_initgroups= 0;
 
 2136   if (setgid(user_info_arg->pw_gid) == -1)
 
 2138     sql_perror(
"setgid");
 
 2141   if (setuid(user_info_arg->pw_uid) == -1)
 
 2143     sql_perror(
"setuid");
 
 2151 static void set_effective_user(
struct passwd *user_info_arg)
 
 2153 #if !defined(__WIN__) 
 2154   DBUG_ASSERT(user_info_arg != 0);
 
 2155   if (setregid((gid_t)-1, user_info_arg->pw_gid) == -1)
 
 2157     sql_perror(
"setregid");
 
 2160   if (setreuid((uid_t)-1, user_info_arg->pw_uid) == -1)
 
 2162     sql_perror(
"setreuid");
 
 2170 static void set_root(
const char *path)
 
 2172 #if !defined(__WIN__) 
 2173   if (chroot(path) == -1)
 
 2175     sql_perror(
"chroot");
 
 2178   my_setwd(
"/", MYF(0));
 
 2189   for (
const struct addrinfo *cur_ai= addrinfo_list; cur_ai != NULL;
 
 2190        cur_ai= cur_ai->ai_next)
 
 2192     if (cur_ai->ai_family != addr_family)
 
 2196                               cur_ai->ai_socktype, cur_ai->ai_protocol);
 
 2198     char ip_addr[INET6_ADDRSTRLEN];
 
 2200     if (vio_getnameinfo(cur_ai->ai_addr, ip_addr, sizeof (ip_addr),
 
 2201                         NULL, 0, NI_NUMERICHOST))
 
 2206     if (mysql_socket_getfd(sock) == INVALID_SOCKET)
 
 2208       sql_print_error(
"Failed to create a socket for %s '%s': errno: %d.",
 
 2209                       (addr_family == AF_INET) ? 
"IPv4" : 
"IPv6",
 
 2210                       (
const char *) ip_addr,
 
 2211                       (
int) socket_errno);
 
 2216     sql_print_information(
"Server socket created on IP: '%s'.",
 
 2217                           (
const char *) ip_addr);
 
 2219     *use_addrinfo= (
struct addrinfo *)cur_ai;
 
 2227 static void network_init(
void)
 
 2229 #ifdef HAVE_SYS_UN_H 
 2230   struct sockaddr_un  UNIXaddr;
 
 2237   char port_buf[NI_MAXSERV];
 
 2238   DBUG_ENTER(
"network_init");
 
 2241   if (MYSQL_CALLBACK_ELSE(thread_scheduler, init, (), 0))
 
 2246   if (report_port == 0)
 
 2248     report_port= mysqld_port;
 
 2252   if (!opt_disable_networking)
 
 2253     DBUG_ASSERT(report_port != 0);
 
 2256   if (mysqld_port != 0 && !opt_disable_networking && !opt_bootstrap)
 
 2261     const char *bind_address_str= NULL;
 
 2262     const char *ipv6_all_addresses= 
"::";
 
 2263     const char *ipv4_all_addresses= 
"0.0.0.0";
 
 2265     sql_print_information(
"Server hostname (bind-address): '%s'; port: %d",
 
 2266                           my_bind_addr_str, mysqld_port);
 
 2270     memset(&hints, 0, 
sizeof (hints));
 
 2271     hints.ai_flags= AI_PASSIVE;
 
 2272     hints.ai_socktype= SOCK_STREAM;
 
 2273     hints.ai_family= AF_UNSPEC;
 
 2275     my_snprintf(port_buf, NI_MAXSERV, 
"%d", mysqld_port);
 
 2277     if (strcasecmp(my_bind_addr_str, MY_BIND_ALL_ADDRESSES) == 0)
 
 2286       bool ipv6_available= 
false;
 
 2288       if (!getaddrinfo(ipv6_all_addresses, port_buf, &hints, &ai))
 
 2298         ipv6_available= mysql_socket_getfd(s) != INVALID_SOCKET;
 
 2305         sql_print_information(
"IPv6 is available.");
 
 2309         bind_address_str= ipv6_all_addresses;
 
 2313         sql_print_information(
"IPv6 is not available.");
 
 2317         if (getaddrinfo(ipv4_all_addresses, port_buf, &hints, &ai))
 
 2319           sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR));
 
 2320           sql_print_error(
"Can't start server: cannot resolve hostname!");
 
 2324         bind_address_str= ipv4_all_addresses;
 
 2329       if (getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai))
 
 2331         sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR));  
 
 2332         sql_print_error(
"Can't start server: cannot resolve hostname!");
 
 2336       bind_address_str= my_bind_addr_str;
 
 2340     for (
struct addrinfo *cur_ai= ai; cur_ai != NULL; cur_ai= cur_ai->ai_next)
 
 2342       char ip_addr[INET6_ADDRSTRLEN];
 
 2344       if (vio_getnameinfo(cur_ai->ai_addr, ip_addr, sizeof (ip_addr),
 
 2345                           NULL, 0, NI_NUMERICHOST))
 
 2347         sql_print_error(
"Fails to print out IP-address.");
 
 2351       sql_print_information(
"  - '%s' resolves to '%s';",
 
 2352                             bind_address_str, ip_addr);
 
 2367     if (mysql_socket_getfd(ip_sock) == INVALID_SOCKET)
 
 2371     if (mysql_socket_getfd(ip_sock) == INVALID_SOCKET)
 
 2373       sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR));  
 
 2377     mysql_socket_set_thread_owner(ip_sock);
 
 2398     if (a->ai_family == AF_INET6)
 
 2403                                   (
char *) &arg, 
sizeof (arg)))
 
 2405         sql_print_warning(
"Failed to reset IPV6_V6ONLY flag (error: %d). " 
 2406                           "The server will listen to IPv6 addresses only.",
 
 2407                           (
int) socket_errno);
 
 2419     for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
 
 2422           (socket_errno != SOCKET_EADDRINUSE) ||
 
 2423           (waited >= mysqld_port_timeout))
 
 2425       sql_print_information(
"Retrying bind on TCP/IP port %u", mysqld_port);
 
 2426       this_wait= retry * retry / 3 + 1;
 
 2432       DBUG_PRINT(
"error",(
"Got error: %d from bind",socket_errno));
 
 2433       sql_perror(
"Can't start server: Bind on TCP/IP port");
 
 2434       sql_print_error(
"Do you already have another mysqld server running on port: %d ?",mysqld_port);
 
 2439       sql_perror(
"Can't start server: listen() on TCP/IP port");
 
 2440       sql_print_error(
"listen() on TCP/IP failed with error %d",
 
 2448   if (Service.IsNT() && mysqld_unix_port[0] && !opt_bootstrap &&
 
 2449       opt_enable_named_pipe)
 
 2451     strxnmov(pipe_name, 
sizeof(pipe_name)-1, 
"\\\\.\\pipe\\",
 
 2452        mysqld_unix_port, NullS);
 
 2453     memset(&saPipeSecurity, 0, 
sizeof(saPipeSecurity));
 
 2454     memset(&sdPipeDescriptor, 0, 
sizeof(sdPipeDescriptor));
 
 2455     if (!InitializeSecurityDescriptor(&sdPipeDescriptor,
 
 2456               SECURITY_DESCRIPTOR_REVISION))
 
 2458       sql_perror(
"Can't start server : Initialize security descriptor");
 
 2461     if (!SetSecurityDescriptorDacl(&sdPipeDescriptor, TRUE, NULL, FALSE))
 
 2463       sql_perror(
"Can't start server : Set security descriptor");
 
 2466     saPipeSecurity.nLength = 
sizeof(SECURITY_ATTRIBUTES);
 
 2467     saPipeSecurity.lpSecurityDescriptor = &sdPipeDescriptor;
 
 2468     saPipeSecurity.bInheritHandle = FALSE;
 
 2469     if ((hPipe= CreateNamedPipe(pipe_name,
 
 2470         PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED,
 
 2472         PIPE_READMODE_BYTE |
 
 2474         PIPE_UNLIMITED_INSTANCES,
 
 2475         (
int) global_system_variables.net_buffer_length,
 
 2476         (
int) global_system_variables.net_buffer_length,
 
 2477         NMPWAIT_USE_DEFAULT_WAIT,
 
 2478         &saPipeSecurity)) == INVALID_HANDLE_VALUE)
 
 2481   int error=GetLastError();
 
 2482   FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
 
 2483           FORMAT_MESSAGE_FROM_SYSTEM,
 
 2484           NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
 
 2485           (LPTSTR) &lpMsgBuf, 0, NULL );
 
 2486   sql_perror((
char *)lpMsgBuf);
 
 2487   LocalFree(lpMsgBuf);
 
 2493 #if defined(HAVE_SYS_UN_H) 
 2497   if (mysqld_unix_port[0] && !opt_bootstrap)
 
 2499     DBUG_PRINT(
"general",(
"UNIX Socket is %s",mysqld_unix_port));
 
 2501     if (strlen(mysqld_unix_port) > (
sizeof(UNIXaddr.sun_path) - 1))
 
 2503       sql_print_error(
"The socket file path is too long (> %u): %s",
 
 2504                       (uint) 
sizeof(UNIXaddr.sun_path) - 1, mysqld_unix_port);
 
 2510     if (mysql_socket_getfd(unix_sock) < 0)
 
 2512       sql_perror(
"Can't start server : UNIX Socket "); 
 
 2516     mysql_socket_set_thread_owner(unix_sock);
 
 2518     memset(&UNIXaddr, 0, 
sizeof(UNIXaddr));
 
 2519     UNIXaddr.sun_family = AF_UNIX;
 
 2520     strmov(UNIXaddr.sun_path, mysqld_unix_port);
 
 2521     (void) unlink(mysqld_unix_port);
 
 2526     if (
mysql_socket_bind(unix_sock, reinterpret_cast<struct sockaddr *> (&UNIXaddr),
 
 2527                           sizeof(UNIXaddr)) < 0)
 
 2529       sql_perror(
"Can't start server : Bind on unix socket"); 
 
 2530       sql_print_error(
"Do you already have another mysqld server running on socket: %s ?",mysqld_unix_port);
 
 2533     umask(((~my_umask) & 0666));
 
 2534 #if defined(S_IFSOCK) && defined(SECURE_SOCKETS) 
 2535     (void) chmod(mysqld_unix_port,S_IFSOCK);  
 
 2538       sql_print_warning(
"listen() on Unix socket failed with error %d",
 
 2542   DBUG_PRINT(
"info",(
"server started"));
 
 2549 #ifndef EMBEDDED_LIBRARY 
 2559 void close_connection(THD *thd, uint sql_errno)
 
 2561   DBUG_ENTER(
"close_connection");
 
 2568   MYSQL_CONNECTION_DONE((
int) sql_errno, thd->thread_id);
 
 2570   if (MYSQL_CONNECTION_DONE_ENABLED())
 
 2574   MYSQL_AUDIT_NOTIFY_CONNECTION_DISCONNECT(thd, sql_errno);
 
 2582 extern "C" sig_handler end_thread_signal(
int sig __attribute__((unused)))
 
 2584   THD *thd=current_thd;
 
 2585   my_safe_printf_stderr(
"end_thread_signal %p", thd);
 
 2586   if (thd && ! thd->bootstrap)
 
 2588     statistic_increment(killed_threads, &LOCK_status);
 
 2589     MYSQL_CALLBACK(thread_scheduler, end_thread, (thd,0)); 
 
 2602 void thd_release_resources(THD *thd)
 
 2604   thd->release_resources();
 
 2614 void dec_connection_count()
 
 2625 void destroy_thd(THD *thd)
 
 2640 static bool block_until_new_connection()
 
 2643   if (blocked_pthread_count < max_blocked_pthreads &&
 
 2644       !abort_loop && !kill_blocked_pthreads_flag)
 
 2647     DBUG_PRINT(
"info", (
"Blocking pthread for reuse"));
 
 2648     blocked_pthread_count++;
 
 2656     DBUG_ASSERT( ! _db_is_pushed_());
 
 2658 #ifdef HAVE_PSI_THREAD_INTERFACE 
 2663     PSI_THREAD_CALL(delete_current_thread)();
 
 2667     while (!abort_loop && !wake_pthread && !kill_blocked_pthreads_flag)
 
 2670     blocked_pthread_count--;
 
 2671     if (kill_blocked_pthreads_flag)
 
 2677       DBUG_ASSERT(!waiting_thd_list->empty());
 
 2678       thd= waiting_thd_list->front();
 
 2679       waiting_thd_list->pop_front();
 
 2680       DBUG_PRINT(
"info", (
"waiting_thd_list->pop %p", thd));
 
 2682       thd->thread_stack= (
char*) &thd;          
 
 2683       (void) thd->store_globals();
 
 2685 #ifdef HAVE_PSI_THREAD_INTERFACE 
 2690       PSI_thread *psi= PSI_THREAD_CALL(new_thread)
 
 2691         (key_thread_one_connection, thd, thd->thread_id);
 
 2692       PSI_THREAD_CALL(set_thread)(psi);
 
 2700       thd->mysys_var->abort= 0;
 
 2701       thd->thr_create_utime= thd->start_utime= my_micro_time();
 
 2702       add_global_thread(thd);
 
 2727 bool one_thread_per_connection_end(THD *thd, 
bool block_pthread)
 
 2729   DBUG_ENTER(
"one_thread_per_connection_end");
 
 2730   DBUG_PRINT(
"info", (
"thd %p block_pthread %d", thd, (
int) block_pthread));
 
 2732   thd->release_resources();
 
 2733   dec_connection_count();
 
 2741   DBUG_EXECUTE_IF(
"sleep_after_lock_thread_count_before_delete_thd", sleep(5););
 
 2742   remove_global_thread(thd);
 
 2743   if (kill_blocked_pthreads_flag)
 
 2746     block_pthread= 
false;
 
 2750 #ifndef EMBEDDED_LIBRARY 
 2751   ERR_remove_state(0);
 
 2762     block_pthread= block_until_new_connection();
 
 2768   DBUG_PRINT(
"signal", (
"Broadcasting COND_thread_count"));
 
 2778 void kill_blocked_pthreads()
 
 2781   kill_blocked_pthreads_flag++;
 
 2782   while (blocked_pthread_count)
 
 2787   kill_blocked_pthreads_flag--;
 
 2792 #ifdef THREAD_SPECIFIC_SIGPIPE 
 2799 extern "C" sig_handler abort_thread(
int sig __attribute__((unused)))
 
 2801   THD *thd=current_thd;
 
 2802   DBUG_ENTER(
"abort_thread");
 
 2804     thd->killed= THD::KILL_CONNECTION;
 
 2816 #if defined(__WIN__) 
 2828 static BOOL WINAPI console_event_handler( DWORD 
type )
 
 2830   DBUG_ENTER(
"console_event_handler");
 
 2831 #ifndef EMBEDDED_LIBRARY 
 2832   if(type == CTRL_C_EVENT)
 
 2840 #ifndef EMBEDDED_LIBRARY 
 2845        sql_print_warning(
"CTRL-C ignored during startup");
 
 2855 #ifdef DEBUG_UNHANDLED_EXCEPTION_FILTER 
 2856 #define DEBUGGER_ATTACH_TIMEOUT 120 
 2861 static void wait_for_debugger(
int timeout_sec)
 
 2863    if(!IsDebuggerPresent())
 
 2866      printf(
"Waiting for debugger to attach, pid=%u\n",GetCurrentProcessId());
 
 2868      for(i= 0; i < timeout_sec; i++)
 
 2871        if(IsDebuggerPresent())
 
 2878      printf(
"pid=%u, debugger not attached after %d seconds, resuming\n",GetCurrentProcessId(),
 
 2885 LONG WINAPI my_unhandler_exception_filter(EXCEPTION_POINTERS *ex_pointers)
 
 2887    static BOOL first_time= TRUE;
 
 2895      return EXCEPTION_EXECUTE_HANDLER;
 
 2898 #ifdef DEBUG_UNHANDLED_EXCEPTION_FILTER 
 2906   wait_for_debugger(DEBUGGER_ATTACH_TIMEOUT);
 
 2910     my_set_exception_pointers(ex_pointers);
 
 2911     handle_fatal_signal(ex_pointers->ExceptionRecord->ExceptionCode);
 
 2913   __except(EXCEPTION_EXECUTE_HANDLER)
 
 2916     const char msg[] = 
"Got exception in exception handler!\n";
 
 2917     WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),msg, 
sizeof(msg)-1,
 
 2926   return EXCEPTION_CONTINUE_SEARCH;
 
 2930 void my_init_signals(
void)
 
 2933     SetConsoleCtrlHandler(console_event_handler,TRUE);
 
 2936   _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
 
 2937   _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
 
 2938   _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
 
 2939   _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
 
 2940   _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
 
 2941   _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
 
 2950   SetErrorMode(SetErrorMode(0) | SEM_FAILCRITICALERRORS
 
 2951                                | SEM_NOOPENFILEERRORBOX);
 
 2952   SetUnhandledExceptionFilter(my_unhandler_exception_filter);
 
 2956 static void start_signal_handler(
void)
 
 2958 #ifndef EMBEDDED_LIBRARY 
 2966 static void check_data_home(
const char *path)
 
 2972 #if BACKTRACE_DEMANGLE 
 2974 extern "C" char *my_demangle(
const char *mangled_name, 
int *status)
 
 2976   return abi::__cxa_demangle(mangled_name, NULL, NULL, status);
 
 2981 #if !defined(__WIN__) 
 2982 #ifndef SA_RESETHAND 
 2983 #define SA_RESETHAND 0 
 2986 #define SA_NODEFER 0 
 2989 #ifndef EMBEDDED_LIBRARY 
 2991 void my_init_signals(
void)
 
 2995   DBUG_ENTER(
"my_init_signals");
 
 2997   my_sigset(THR_SERVER_ALARM,print_signal_warning); 
 
 2999   if (!(test_flags & TEST_NO_STACKTRACE) || (test_flags & TEST_CORE_ON_SIGNAL))
 
 3001     sa.sa_flags = SA_RESETHAND | SA_NODEFER;
 
 3002     sigemptyset(&sa.sa_mask);
 
 3003     sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
 
 3005 #ifdef HAVE_STACKTRACE 
 3006     my_init_stacktrace();
 
 3008 #if defined(__amiga__) 
 3009     sa.sa_handler=(void(*)())handle_fatal_signal;
 
 3011     sa.sa_handler=handle_fatal_signal;
 
 3022 #ifdef HAVE_GETRLIMIT 
 3023   if (test_flags & TEST_CORE_ON_SIGNAL)
 
 3027     rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
 
 3028     if (setrlimit(RLIMIT_CORE, &rl) && log_warnings)
 
 3029       sql_print_warning(
"setrlimit could not change the size of core files to 'infinity';  We may not be able to generate a core file on signals");
 
 3032   (void) sigemptyset(&
set);
 
 3033   my_sigset(SIGPIPE,SIG_IGN);
 
 3034   sigaddset(&
set,SIGPIPE);
 
 3035 #ifndef IGNORE_SIGHUP_SIGQUIT 
 3036   sigaddset(&
set,SIGQUIT);
 
 3037   sigaddset(&
set,SIGHUP);
 
 3039   sigaddset(&
set,SIGTERM);
 
 3042   sigemptyset(&sa.sa_mask);
 
 3044   sa.sa_handler = print_signal_warning;
 
 3047   sa.sa_handler = print_signal_warning;
 
 3050   sigaddset(&
set,SIGTSTP);
 
 3052   if (thd_lib_detected != THD_LIB_LT)
 
 3053     sigaddset(&
set,THR_SERVER_ALARM);
 
 3054   if (test_flags & TEST_SIGINT)
 
 3056     my_sigset(thr_kill_signal, end_thread_signal);
 
 3058     sigdelset(&
set, thr_kill_signal);
 
 3061     sigaddset(&
set,SIGINT);
 
 3062   sigprocmask(SIG_SETMASK,&
set,NULL);
 
 3063   pthread_sigmask(SIG_SETMASK,&
set,NULL);
 
 3068 static void start_signal_handler(
void)
 
 3071   pthread_attr_t thr_attr;
 
 3072   DBUG_ENTER(
"start_signal_handler");
 
 3074   (void) pthread_attr_init(&thr_attr);
 
 3075 #if !defined(HAVE_DEC_3_2_THREADS) 
 3076   pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_SYSTEM);
 
 3077   (void) pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
 
 3080   pthread_attr_getguardsize(&thr_attr, &guardize);
 
 3082 #if defined(__ia64__) || defined(__ia64) 
 3087   guardize= my_thread_stack_size;
 
 3090   pthread_attr_setstacksize(&thr_attr, my_thread_stack_size + guardize);
 
 3095                                   &signal_thread, &thr_attr, signal_hand, 0)))
 
 3097     sql_print_error(
"Can't create interrupt-thread (error %d, errno: %d)",
 
 3104   (void) pthread_attr_destroy(&thr_attr);
 
 3111 pthread_handler_t signal_hand(
void *arg __attribute__((unused)))
 
 3116   signal_thread_in_use= 1;
 
 3123   init_thr_alarm(thread_scheduler->max_threads +
 
 3124      global_system_variables.max_insert_delayed_threads + 10);
 
 3125   if (thd_lib_detected != THD_LIB_LT && (test_flags & TEST_SIGINT))
 
 3127     (void) sigemptyset(&
set);     
 
 3128     (void) sigaddset(&
set,SIGINT);    
 
 3129     (void) pthread_sigmask(SIG_UNBLOCK,&
set,NULL);
 
 3131   (void) sigemptyset(&
set);     
 
 3132 #ifdef USE_ONE_SIGNAL_HAND 
 3133   (void) sigaddset(&
set,THR_SERVER_ALARM);  
 
 3135 #ifndef IGNORE_SIGHUP_SIGQUIT 
 3136   (void) sigaddset(&
set,SIGQUIT);
 
 3137   (void) sigaddset(&
set,SIGHUP);
 
 3139   (void) sigaddset(&
set,SIGTERM);
 
 3140   (void) sigaddset(&
set,SIGTSTP);
 
 3165   while (!mysqld_server_started)
 
 3172     if (shutdown_in_progress && !abort_loop)
 
 3178       while ((error=my_sigwait(&
set,&sig)) == EINTR) ;
 
 3182       signal_thread_in_use= 0;
 
 3191       sql_print_information(
"Got signal %d to shutdown mysqld",sig);
 
 3194       logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_FILE:LOG_NONE,
 
 3195                           opt_log ? LOG_FILE:LOG_NONE);
 
 3196       DBUG_PRINT(
"info",(
"Got signal: %d  abort_loop: %d",sig,abort_loop));
 
 3200 #ifdef HAVE_PSI_THREAD_INTERFACE 
 3202         PSI_THREAD_CALL(delete_current_thread)();
 
 3204 #ifdef USE_ONE_SIGNAL_HAND 
 3207                                         &tmp, &connection_attrib,
 
 3210           sql_print_error(
"Can't create thread to kill server (errno= %d)",
 
 3213         kill_server((
void*) sig); 
 
 3221   mysql_print_status();   
 
 3222   reload_acl_and_cache((THD*) 0,
 
 3223            (REFRESH_LOG | REFRESH_TABLES | REFRESH_FAST |
 
 3225             REFRESH_THREADS | REFRESH_HOSTS),
 
 3229       if (log_output_options & LOG_NONE)
 
 3231         logger.set_handlers(LOG_FILE,
 
 3232                             opt_slow_log ? LOG_TABLE : LOG_NONE,
 
 3233                             opt_log ? LOG_TABLE : LOG_NONE);
 
 3237         logger.set_handlers(LOG_FILE,
 
 3238                             opt_slow_log ? log_output_options : LOG_NONE,
 
 3239                             opt_log ? log_output_options : LOG_NONE);
 
 3242 #ifdef USE_ONE_SIGNAL_HAND 
 3243     case THR_SERVER_ALARM:
 
 3249       sql_print_warning(
"Got signal: %d  error: %d",sig,error); 
 
 3257 static void check_data_home(
const char *path)
 
 3269 extern "C" void my_message_sql(uint error, 
const char *str, myf MyFlags);
 
 3271 void my_message_sql(uint error, 
const char *str, myf MyFlags)
 
 3273   THD *thd= current_thd;
 
 3274   DBUG_ENTER(
"my_message_sql");
 
 3275   DBUG_PRINT(
"error", (
"error: %u  message: '%s'", error, str));
 
 3277   DBUG_ASSERT(str != NULL);
 
 3291     DBUG_ASSERT(strncmp(str, 
"MyISAM table", 12) == 0);
 
 3292     error= ER_UNKNOWN_ERROR;
 
 3295   mysql_audit_general(thd, MYSQL_AUDIT_GENERAL_ERROR, error, str);
 
 3299     if (MyFlags & ME_FATALERROR)
 
 3300       thd->is_fatal_error= 1;
 
 3301     (void) thd->raise_condition(error,
 
 3303                                 Sql_condition::WARN_LEVEL_ERROR,
 
 3308   DBUG_EXECUTE_IF(
"simulate_out_of_memory", DBUG_VOID_RETURN;);
 
 3310   if (!thd || MyFlags & ME_NOREFRESH)
 
 3311     sql_print_error(
"%s: %s",my_progname,str); 
 
 3316 #ifndef EMBEDDED_LIBRARY 
 3317 extern "C" void *my_str_malloc_mysqld(
size_t size);
 
 3318 extern "C" void my_str_free_mysqld(
void *ptr);
 
 3319 extern "C" void *my_str_realloc_mysqld(
void *ptr, 
size_t size);
 
 3321 void *my_str_malloc_mysqld(
size_t size)
 
 3323   return my_malloc(size, MYF(MY_FAE));
 
 3327 void my_str_free_mysqld(
void *ptr)
 
 3332 void *my_str_realloc_mysqld(
void *ptr, 
size_t size)
 
 3334   return my_realloc(ptr, size, MYF(MY_FAE));
 
 3341 pthread_handler_t handle_shutdown(
void *arg)
 
 3347   PeekMessage(&msg, NULL, 1, 65534,PM_NOREMOVE);
 
 3348 #if !defined(EMBEDDED_LIBRARY) 
 3349   if (WaitForSingleObject(hEventShutdown,INFINITE)==WAIT_OBJECT_0)
 
 3351      kill_server(MYSQL_KILL_SIGNAL);
 
 3356 const char *load_default_groups[]= {
 
 3357 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE 
 3360 "mysqld",
"server", MYSQL_BASE_VERSION, 0, 0};
 
 3362 #if defined(__WIN__) && !defined(EMBEDDED_LIBRARY) 
 3363 static const int load_default_groups_sz=
 
 3364 sizeof(load_default_groups)/
sizeof(load_default_groups[0]);
 
 3367 #ifndef EMBEDDED_LIBRARY 
 3377 check_enough_stack_size(
int recurse_level)
 
 3380   if (recurse_level % 16 != 0)
 
 3383   THD *my_thd= current_thd;
 
 3403 static bool init_global_datetime_format(timestamp_type format_type,
 
 3410   format->format.length= strlen(format->format.str);
 
 3412   if (parse_date_time_format(format_type, format))
 
 3414     fprintf(stderr, 
"Wrong date/time format specifier: %s\n",
 
 3415             format->format.str);
 
 3422   {
"admin_commands",       (
char*) offsetof(
STATUS_VAR, com_other), SHOW_LONG_STATUS},
 
 3423   {
"assign_to_keycache",   (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ASSIGN_TO_KEYCACHE]), SHOW_LONG_STATUS},
 
 3424   {
"alter_db",             (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_DB]), SHOW_LONG_STATUS},
 
 3425   {
"alter_db_upgrade",     (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_DB_UPGRADE]), SHOW_LONG_STATUS},
 
 3426   {
"alter_event",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_EVENT]), SHOW_LONG_STATUS},
 
 3427   {
"alter_function",       (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_FUNCTION]), SHOW_LONG_STATUS},
 
 3428   {
"alter_procedure",      (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_PROCEDURE]), SHOW_LONG_STATUS},
 
 3429   {
"alter_server",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_SERVER]), SHOW_LONG_STATUS},
 
 3430   {
"alter_table",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_TABLE]), SHOW_LONG_STATUS},
 
 3431   {
"alter_tablespace",     (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_TABLESPACE]), SHOW_LONG_STATUS},
 
 3432   {
"alter_user",           (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_USER]), SHOW_LONG_STATUS},
 
 3433   {
"analyze",              (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ANALYZE]), SHOW_LONG_STATUS},
 
 3434   {
"begin",                (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_BEGIN]), SHOW_LONG_STATUS},
 
 3435   {
"binlog",               (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_BINLOG_BASE64_EVENT]), SHOW_LONG_STATUS},
 
 3436   {
"call_procedure",       (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CALL]), SHOW_LONG_STATUS},
 
 3437   {
"change_db",            (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CHANGE_DB]), SHOW_LONG_STATUS},
 
 3438   {
"change_master",        (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CHANGE_MASTER]), SHOW_LONG_STATUS},
 
 3439   {
"check",                (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CHECK]), SHOW_LONG_STATUS},
 
 3440   {
"checksum",             (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CHECKSUM]), SHOW_LONG_STATUS},
 
 3441   {
"commit",               (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_COMMIT]), SHOW_LONG_STATUS},
 
 3442   {
"create_db",            (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_DB]), SHOW_LONG_STATUS},
 
 3443   {
"create_event",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_EVENT]), SHOW_LONG_STATUS},
 
 3444   {
"create_function",      (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_SPFUNCTION]), SHOW_LONG_STATUS},
 
 3445   {
"create_index",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_INDEX]), SHOW_LONG_STATUS},
 
 3446   {
"create_procedure",     (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_PROCEDURE]), SHOW_LONG_STATUS},
 
 3447   {
"create_server",        (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_SERVER]), SHOW_LONG_STATUS},
 
 3448   {
"create_table",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_TABLE]), SHOW_LONG_STATUS},
 
 3449   {
"create_trigger",       (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_TRIGGER]), SHOW_LONG_STATUS},
 
 3450   {
"create_udf",           (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_FUNCTION]), SHOW_LONG_STATUS},
 
 3451   {
"create_user",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_USER]), SHOW_LONG_STATUS},
 
 3452   {
"create_view",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_VIEW]), SHOW_LONG_STATUS},
 
 3453   {
"dealloc_sql",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DEALLOCATE_PREPARE]), SHOW_LONG_STATUS},
 
 3454   {
"delete",               (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DELETE]), SHOW_LONG_STATUS},
 
 3455   {
"delete_multi",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DELETE_MULTI]), SHOW_LONG_STATUS},
 
 3456   {
"do",                   (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DO]), SHOW_LONG_STATUS},
 
 3457   {
"drop_db",              (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DROP_DB]), SHOW_LONG_STATUS},
 
 3458   {
"drop_event",           (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DROP_EVENT]), SHOW_LONG_STATUS},
 
 3459   {
"drop_function",        (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DROP_FUNCTION]), SHOW_LONG_STATUS},
 
 3460   {
"drop_index",           (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DROP_INDEX]), SHOW_LONG_STATUS},
 
 3461   {
"drop_procedure",       (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DROP_PROCEDURE]), SHOW_LONG_STATUS},
 
 3462   {
"drop_server",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DROP_SERVER]), SHOW_LONG_STATUS},
 
 3463   {
"drop_table",           (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DROP_TABLE]), SHOW_LONG_STATUS},
 
 3464   {
"drop_trigger",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DROP_TRIGGER]), SHOW_LONG_STATUS},
 
 3465   {
"drop_user",            (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DROP_USER]), SHOW_LONG_STATUS},
 
 3466   {
"drop_view",            (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_DROP_VIEW]), SHOW_LONG_STATUS},
 
 3467   {
"empty_query",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_EMPTY_QUERY]), SHOW_LONG_STATUS},
 
 3468   {
"execute_sql",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_EXECUTE]), SHOW_LONG_STATUS},
 
 3469   {
"flush",                (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_FLUSH]), SHOW_LONG_STATUS},
 
 3470   {
"get_diagnostics",      (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_GET_DIAGNOSTICS]), SHOW_LONG_STATUS},
 
 3471   {
"grant",                (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_GRANT]), SHOW_LONG_STATUS},
 
 3472   {
"ha_close",             (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_HA_CLOSE]), SHOW_LONG_STATUS},
 
 3473   {
"ha_open",              (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_HA_OPEN]), SHOW_LONG_STATUS},
 
 3474   {
"ha_read",              (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_HA_READ]), SHOW_LONG_STATUS},
 
 3475   {
"help",                 (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_HELP]), SHOW_LONG_STATUS},
 
 3476   {
"insert",               (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_INSERT]), SHOW_LONG_STATUS},
 
 3477   {
"insert_select",        (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_INSERT_SELECT]), SHOW_LONG_STATUS},
 
 3478   {
"install_plugin",       (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_INSTALL_PLUGIN]), SHOW_LONG_STATUS},
 
 3479   {
"kill",                 (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_KILL]), SHOW_LONG_STATUS},
 
 3480   {
"load",                 (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_LOAD]), SHOW_LONG_STATUS},
 
 3481   {
"lock_tables",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_LOCK_TABLES]), SHOW_LONG_STATUS},
 
 3482   {
"optimize",             (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_OPTIMIZE]), SHOW_LONG_STATUS},
 
 3483   {
"preload_keys",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_PRELOAD_KEYS]), SHOW_LONG_STATUS},
 
 3484   {
"prepare_sql",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_PREPARE]), SHOW_LONG_STATUS},
 
 3485   {
"purge",                (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_PURGE]), SHOW_LONG_STATUS},
 
 3486   {
"purge_before_date",    (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_PURGE_BEFORE]), SHOW_LONG_STATUS},
 
 3487   {
"release_savepoint",    (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_RELEASE_SAVEPOINT]), SHOW_LONG_STATUS},
 
 3488   {
"rename_table",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_RENAME_TABLE]), SHOW_LONG_STATUS},
 
 3489   {
"rename_user",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_RENAME_USER]), SHOW_LONG_STATUS},
 
 3490   {
"repair",               (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_REPAIR]), SHOW_LONG_STATUS},
 
 3491   {
"replace",              (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_REPLACE]), SHOW_LONG_STATUS},
 
 3492   {
"replace_select",       (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_REPLACE_SELECT]), SHOW_LONG_STATUS},
 
 3493   {
"reset",                (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_RESET]), SHOW_LONG_STATUS},
 
 3494   {
"resignal",             (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_RESIGNAL]), SHOW_LONG_STATUS},
 
 3495   {
"revoke",               (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_REVOKE]), SHOW_LONG_STATUS},
 
 3496   {
"revoke_all",           (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_REVOKE_ALL]), SHOW_LONG_STATUS},
 
 3497   {
"rollback",             (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ROLLBACK]), SHOW_LONG_STATUS},
 
 3498   {
"rollback_to_savepoint",(
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_ROLLBACK_TO_SAVEPOINT]), SHOW_LONG_STATUS},
 
 3499   {
"savepoint",            (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SAVEPOINT]), SHOW_LONG_STATUS},
 
 3500   {
"select",               (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SELECT]), SHOW_LONG_STATUS},
 
 3501   {
"set_option",           (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SET_OPTION]), SHOW_LONG_STATUS},
 
 3502   {
"signal",               (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SIGNAL]), SHOW_LONG_STATUS},
 
 3503   {
"show_binlog_events",   (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_BINLOG_EVENTS]), SHOW_LONG_STATUS},
 
 3504   {
"show_binlogs",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_BINLOGS]), SHOW_LONG_STATUS},
 
 3505   {
"show_charsets",        (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CHARSETS]), SHOW_LONG_STATUS},
 
 3506   {
"show_collations",      (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_COLLATIONS]), SHOW_LONG_STATUS},
 
 3507   {
"show_create_db",       (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE_DB]), SHOW_LONG_STATUS},
 
 3508   {
"show_create_event",    (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE_EVENT]), SHOW_LONG_STATUS},
 
 3509   {
"show_create_func",     (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE_FUNC]), SHOW_LONG_STATUS},
 
 3510   {
"show_create_proc",     (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE_PROC]), SHOW_LONG_STATUS},
 
 3511   {
"show_create_table",    (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE]), SHOW_LONG_STATUS},
 
 3512   {
"show_create_trigger",  (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE_TRIGGER]), SHOW_LONG_STATUS},
 
 3513   {
"show_databases",       (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_DATABASES]), SHOW_LONG_STATUS},
 
 3514   {
"show_engine_logs",     (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_ENGINE_LOGS]), SHOW_LONG_STATUS},
 
 3515   {
"show_engine_mutex",    (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_ENGINE_MUTEX]), SHOW_LONG_STATUS},
 
 3516   {
"show_engine_status",   (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_ENGINE_STATUS]), SHOW_LONG_STATUS},
 
 3517   {
"show_events",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_EVENTS]), SHOW_LONG_STATUS},
 
 3518   {
"show_errors",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_ERRORS]), SHOW_LONG_STATUS},
 
 3519   {
"show_fields",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_FIELDS]), SHOW_LONG_STATUS},
 
 3520   {
"show_function_code",   (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_FUNC_CODE]), SHOW_LONG_STATUS},
 
 3521   {
"show_function_status", (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STATUS_FUNC]), SHOW_LONG_STATUS},
 
 3522   {
"show_grants",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_GRANTS]), SHOW_LONG_STATUS},
 
 3523   {
"show_keys",            (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_KEYS]), SHOW_LONG_STATUS},
 
 3524   {
"show_master_status",   (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_MASTER_STAT]), SHOW_LONG_STATUS},
 
 3525   {
"show_open_tables",     (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_OPEN_TABLES]), SHOW_LONG_STATUS},
 
 3526   {
"show_plugins",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PLUGINS]), SHOW_LONG_STATUS},
 
 3527   {
"show_privileges",      (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PRIVILEGES]), SHOW_LONG_STATUS},
 
 3528   {
"show_procedure_code",  (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROC_CODE]), SHOW_LONG_STATUS},
 
 3529   {
"show_procedure_status",(
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STATUS_PROC]), SHOW_LONG_STATUS},
 
 3530   {
"show_processlist",     (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROCESSLIST]), SHOW_LONG_STATUS},
 
 3531   {
"show_profile",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROFILE]), SHOW_LONG_STATUS},
 
 3532   {
"show_profiles",        (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROFILES]), SHOW_LONG_STATUS},
 
 3533   {
"show_relaylog_events", (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_RELAYLOG_EVENTS]), SHOW_LONG_STATUS},
 
 3534   {
"show_slave_hosts",     (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_HOSTS]), SHOW_LONG_STATUS},
 
 3535   {
"show_slave_status",    (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_STAT]), SHOW_LONG_STATUS},
 
 3536   {
"show_status",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STATUS]), SHOW_LONG_STATUS},
 
 3537   {
"show_storage_engines", (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STORAGE_ENGINES]), SHOW_LONG_STATUS},
 
 3538   {
"show_table_status",    (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLE_STATUS]), SHOW_LONG_STATUS},
 
 3539   {
"show_tables",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLES]), SHOW_LONG_STATUS},
 
 3540   {
"show_triggers",        (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TRIGGERS]), SHOW_LONG_STATUS},
 
 3541   {
"show_variables",       (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_VARIABLES]), SHOW_LONG_STATUS},
 
 3542   {
"show_warnings",        (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_WARNS]), SHOW_LONG_STATUS},
 
 3543   {
"slave_start",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SLAVE_START]), SHOW_LONG_STATUS},
 
 3544   {
"slave_stop",           (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_SLAVE_STOP]), SHOW_LONG_STATUS},
 
 3545   {
"stmt_close",           (
char*) offsetof(
STATUS_VAR, com_stmt_close), SHOW_LONG_STATUS},
 
 3546   {
"stmt_execute",         (
char*) offsetof(
STATUS_VAR, com_stmt_execute), SHOW_LONG_STATUS},
 
 3547   {
"stmt_fetch",           (
char*) offsetof(
STATUS_VAR, com_stmt_fetch), SHOW_LONG_STATUS},
 
 3548   {
"stmt_prepare",         (
char*) offsetof(
STATUS_VAR, com_stmt_prepare), SHOW_LONG_STATUS},
 
 3549   {
"stmt_reprepare",       (
char*) offsetof(
STATUS_VAR, com_stmt_reprepare), SHOW_LONG_STATUS},
 
 3550   {
"stmt_reset",           (
char*) offsetof(
STATUS_VAR, com_stmt_reset), SHOW_LONG_STATUS},
 
 3551   {
"stmt_send_long_data",  (
char*) offsetof(
STATUS_VAR, com_stmt_send_long_data), SHOW_LONG_STATUS},
 
 3552   {
"truncate",             (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_TRUNCATE]), SHOW_LONG_STATUS},
 
 3553   {
"uninstall_plugin",     (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_UNINSTALL_PLUGIN]), SHOW_LONG_STATUS},
 
 3554   {
"unlock_tables",        (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_UNLOCK_TABLES]), SHOW_LONG_STATUS},
 
 3555   {
"update",               (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_UPDATE]), SHOW_LONG_STATUS},
 
 3556   {
"update_multi",         (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_UPDATE_MULTI]), SHOW_LONG_STATUS},
 
 3557   {
"xa_commit",            (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_XA_COMMIT]),SHOW_LONG_STATUS},
 
 3558   {
"xa_end",               (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_XA_END]),SHOW_LONG_STATUS},
 
 3559   {
"xa_prepare",           (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_XA_PREPARE]),SHOW_LONG_STATUS},
 
 3560   {
"xa_recover",           (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_XA_RECOVER]),SHOW_LONG_STATUS},
 
 3561   {
"xa_rollback",          (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_XA_ROLLBACK]),SHOW_LONG_STATUS},
 
 3562   {
"xa_start",             (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_XA_START]),SHOW_LONG_STATUS},
 
 3563   {NullS, NullS, SHOW_LONG}
 
 3566 LEX_CSTRING sql_statement_names[(uint) SQLCOM_END + 1];
 
 3568 void init_sql_statement_names()
 
 3570   static LEX_CSTRING empty= { C_STRING_WITH_LEN(
"") };
 
 3572   char *first_com= (
char*) offsetof(
STATUS_VAR, com_stat[0]);
 
 3573   char *last_com= (
char*) offsetof(
STATUS_VAR, com_stat[(uint) SQLCOM_END]);
 
 3574   int record_size= (
char*) offsetof(
STATUS_VAR, com_stat[1])
 
 3580   for (i= 0; i < ((uint) SQLCOM_END + 1); i++)
 
 3581     sql_statement_names[i]= empty;
 
 3583   SHOW_VAR *var= &com_status_vars[0];
 
 3584   while (var->name != NULL)
 
 3587     if ((first_com <= ptr) && (ptr <= last_com))
 
 3589       com_index= ((int)(ptr - first_com))/record_size;
 
 3590       DBUG_ASSERT(com_index < (uint) SQLCOM_END);
 
 3591       sql_statement_names[com_index].str= var->name;
 
 3593       sql_statement_names[com_index].length= strlen(var->name);
 
 3598   DBUG_ASSERT(strcmp(sql_statement_names[(uint) SQLCOM_SELECT].str, 
"select") == 0);
 
 3599   DBUG_ASSERT(strcmp(sql_statement_names[(uint) SQLCOM_SIGNAL].str, 
"signal") == 0);
 
 3601   sql_statement_names[(uint) SQLCOM_END].str= 
"error";
 
 3604 #ifdef HAVE_PSI_STATEMENT_INTERFACE 
 3605 PSI_statement_info sql_statement_info[(uint) SQLCOM_END + 1];
 
 3606 PSI_statement_info com_statement_info[(uint) COM_END + 1];
 
 3614 void init_sql_statement_info()
 
 3618   for (i= 0; i < ((uint) SQLCOM_END + 1); i++)
 
 3620     sql_statement_info[
i].m_name= sql_statement_names[
i].str;
 
 3621     sql_statement_info[
i].m_flags= 0;
 
 3625   sql_statement_info[(uint) SQLCOM_END].m_name= 
"error";
 
 3626   sql_statement_info[(uint) SQLCOM_END].m_flags= 0;
 
 3629 void init_com_statement_info()
 
 3633   for (index= 0; index < (uint) COM_END + 1; index++)
 
 3635     com_statement_info[
index].m_name= command_name[
index].str;
 
 3636     com_statement_info[
index].m_flags= 0;
 
 3640   com_statement_info[(uint) COM_QUERY].m_flags= PSI_FLAG_MUTABLE;
 
 3651 static inline char *make_default_log_name(
char *buff,
const char* log_ext)
 
 3666 static inline const char *
 
 3667 rpl_make_log_name(
const char *opt,
 
 3671   DBUG_ENTER(
"rpl_make_log_name");
 
 3672   DBUG_PRINT(
"enter", (
"opt: %s, def: %s, ext: %s", opt, def, ext));
 
 3673   char buff[FN_REFLEN];
 
 3674   const char *base= opt ? opt : def;
 
 3675   unsigned int options=
 
 3676     MY_REPLACE_EXT | MY_UNPACK_FILENAME | MY_SAFE_PATH;
 
 3683   if(mysql_real_data_home_ptr == NULL)
 
 3684     mysql_real_data_home_ptr= mysql_real_data_home;
 
 3686   if (fn_format(buff, base, mysql_real_data_home_ptr, ext, options))
 
 3687     DBUG_RETURN(strdup(buff));
 
 3693 int init_common_variables()
 
 3695   umask(((~my_umask) & 0666));
 
 3696   connection_errors_select= 0;
 
 3697   connection_errors_accept= 0;
 
 3698   connection_errors_tcpwrap= 0;
 
 3699   connection_errors_internal= 0;
 
 3700   connection_errors_max_connection= 0;
 
 3701   connection_errors_peer_addr= 0;
 
 3702   my_decimal_set_zero(&decimal_zero); 
 
 3706   server_start_time= flush_status_time= my_time(0);
 
 3710   if (!rpl_filter || !binlog_filter)
 
 3712     sql_perror(
"Could not allocate replication and binlog filters");
 
 3716   if (init_thread_environment() ||
 
 3717       mysql_init_variables())
 
 3720   if (ignore_db_dirs_init())
 
 3726     localtime_r(&server_start_time,&tm_tmp);
 
 3727     strmake(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0],
 
 3728             sizeof(system_time_zone)-1);
 
 3738   global_system_variables.time_zone= my_tz_SYSTEM;
 
 3740 #ifdef HAVE_PSI_INTERFACE 
 3746   mysql_bin_log.set_psi_keys(key_BINLOG_LOCK_index,
 
 3747                              key_BINLOG_LOCK_commit,
 
 3748                              key_BINLOG_LOCK_commit_queue,
 
 3749                              key_BINLOG_LOCK_done,
 
 3750                              key_BINLOG_LOCK_flush_queue,
 
 3751                              key_BINLOG_LOCK_log,
 
 3752                              key_BINLOG_LOCK_sync,
 
 3753                              key_BINLOG_LOCK_sync_queue,
 
 3754                              key_BINLOG_LOCK_xids,
 
 3755                              key_BINLOG_COND_done,
 
 3756                              key_BINLOG_update_cond,
 
 3757                              key_BINLOG_prep_xids_cond,
 
 3759                              key_file_binlog_index);
 
 3768   mysql_bin_log.init_pthread_objects();
 
 3771   if (!IS_TIME_T_VALID_FOR_TIMESTAMP(server_start_time))
 
 3773     sql_print_error(
"This MySQL server doesn't support dates later then 2038");
 
 3777   if (gethostname(glob_hostname,
sizeof(glob_hostname)) < 0)
 
 3779     strmake(glob_hostname, STRING_WITH_LEN(
"localhost"));
 
 3780     sql_print_warning(
"gethostname failed, using '%s' as hostname",
 
 3782     strmake(default_logfile_name, STRING_WITH_LEN(
"mysql"));
 
 3785     strmake(default_logfile_name, glob_hostname,
 
 3786       sizeof(default_logfile_name)-5);
 
 3788   strmake(pidfile_name, default_logfile_name, 
sizeof(pidfile_name)-5);
 
 3789   strmov(fn_ext(pidfile_name),
".pid");    
 
 3804 #ifdef EMBEDDED_LIBRARY 
 3805   default_storage_engine= 
const_cast<char *
>(
"MyISAM");
 
 3807   default_storage_engine= 
const_cast<char *
>(
"InnoDB");
 
 3809   default_tmp_storage_engine= default_storage_engine;
 
 3811   init_default_auth_plugin();
 
 3819   if (add_status_vars(status_vars))
 
 3844   compile_time_assert(
sizeof(com_status_vars)/
sizeof(com_status_vars[0]) - 1 ==
 
 3848   if (get_options(&remaining_argc, &remaining_argv))
 
 3850   set_server_version();
 
 3852 #ifndef EMBEDDED_LIBRARY 
 3853   if (opt_help && !opt_verbose)
 
 3857   DBUG_PRINT("info",("%s  Ver %s for %s on %s\n",my_progname, 
 3858          server_version, SYSTEM_TYPE,MACHINE_TYPE));
 
 3860 #ifdef HAVE_LARGE_PAGES 
 3862   if (opt_large_pages && (opt_large_page_size= my_get_large_page_size()))
 
 3864       DBUG_PRINT(
"info", (
"Large page set, large_page_size = %d",
 
 3865                  opt_large_page_size));
 
 3866       my_use_large_pages= 1;
 
 3867       my_large_page_size= opt_large_page_size;
 
 3878 #ifdef HAVE_SOLARIS_LARGE_PAGES 
 3879 #define LARGE_PAGESIZE (4*1024*1024)   
 3880 #define SUPER_LARGE_PAGESIZE (256*1024*1024)   
 3881   if (opt_large_pages)
 
 3894    size_t max_desired_page_size;
 
 3895    if (opt_super_large_pages)
 
 3896      max_desired_page_size= SUPER_LARGE_PAGESIZE;
 
 3898      max_desired_page_size= LARGE_PAGESIZE;
 
 3899    nelem = getpagesizes(NULL, 0);
 
 3902      size_t *pagesize = (
size_t *) malloc(
sizeof(
size_t) * nelem);
 
 3903      if (pagesize != NULL && getpagesizes(pagesize, nelem) > 0)
 
 3905        size_t max_page_size= 0;
 
 3906        for (
int i= 0; i < nelem; i++)
 
 3908          if (pagesize[i] > max_page_size &&
 
 3909              pagesize[i] <= max_desired_page_size)
 
 3910             max_page_size= pagesize[
i];
 
 3913        if (max_page_size > 0)
 
 3915          struct memcntl_mha mpss;
 
 3917          mpss.mha_cmd= MHA_MAPSIZE_BSSBRK;
 
 3918          mpss.mha_pagesize= max_page_size;
 
 3920          memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mpss, 0, 0);
 
 3921          mpss.mha_cmd= MHA_MAPSIZE_STACK;
 
 3922          memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mpss, 0, 0);
 
 3929   longlong default_value;
 
 3932   if ((default_value= 8 + max_connections / 100) > 100)
 
 3934   var= intern_find_sys_var(STRING_WITH_LEN(
"thread_cache_size"));
 
 3935   var->update_default(default_value);
 
 3938   if ((default_value= 128 + max_connections) > 628 &&
 
 3939       (default_value= 628 + ((max_connections - 500) / 20)) > 2000)
 
 3940     default_value= 2000;
 
 3941   var= intern_find_sys_var(STRING_WITH_LEN(
"host_cache_size"));
 
 3942   var->update_default(default_value);
 
 3945   if (!thread_cache_size_specified &&
 
 3946       (max_blocked_pthreads= 8 + max_connections / 100) > 100)
 
 3947     max_blocked_pthreads= 100;
 
 3950   if (!host_cache_size_specified &&
 
 3956   if (back_log == 0 && (back_log= 50 + max_connections / 5) > 900)
 
 3959   unireg_init(opt_specialflag); 
 
 3960   if (!(my_default_lc_messages=
 
 3961         my_locale_by_name(lc_messages)))
 
 3963     sql_print_error(
"Unknown locale: '%s'", lc_messages);
 
 3966   global_system_variables.lc_messages= my_default_lc_messages;
 
 3972   if (item_create_init())
 
 3975 #ifndef EMBEDDED_LIBRARY 
 3976   my_regex_init(&my_charset_latin1, check_enough_stack_size);
 
 3977   my_string_stack_guard= check_enough_stack_size;
 
 3979   my_regex_init(&my_charset_latin1, NULL);
 
 3989     char *next_character_set_name= strchr(default_character_set_name, 
',');
 
 3990     if (next_character_set_name)
 
 3991       *next_character_set_name++= 
'\0';
 
 3992     if (!(default_charset_info=
 
 3993           get_charset_by_csname(default_character_set_name,
 
 3994                                 MY_CS_PRIMARY, MYF(MY_WME))))
 
 3996       if (next_character_set_name)
 
 3998         default_character_set_name= next_character_set_name;
 
 3999         default_collation_name= 0;          
 
 4008   if (default_collation_name)
 
 4011     default_collation= get_charset_by_name(default_collation_name, MYF(0));
 
 4012     if (!default_collation)
 
 4014 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE 
 4015       buffered_logs.
print();
 
 4016       buffered_logs.cleanup();
 
 4018       sql_print_error(ER_DEFAULT(ER_UNKNOWN_COLLATION), default_collation_name);
 
 4021     if (!my_charset_same(default_charset_info, default_collation))
 
 4023       sql_print_error(ER_DEFAULT(ER_COLLATION_CHARSET_MISMATCH),
 
 4024           default_collation_name,
 
 4025           default_charset_info->csname);
 
 4028     default_charset_info= default_collation;
 
 4031   global_system_variables.collation_server=  default_charset_info;
 
 4032   global_system_variables.collation_database=  default_charset_info;
 
 4034   if (is_supported_parser_charset(default_charset_info))
 
 4036     global_system_variables.collation_connection= default_charset_info;
 
 4037     global_system_variables.character_set_results= default_charset_info;
 
 4038     global_system_variables.character_set_client= default_charset_info;
 
 4042     sql_print_information(
"'%s' can not be used as client character set. " 
 4043                           "'%s' will be used as default client character set.",
 
 4044                           default_charset_info->csname,
 
 4045                           my_charset_latin1.csname);
 
 4046     global_system_variables.collation_connection= &my_charset_latin1;
 
 4047     global_system_variables.character_set_results= &my_charset_latin1;
 
 4048     global_system_variables.character_set_client= &my_charset_latin1;
 
 4051   if (!(character_set_filesystem=
 
 4052         get_charset_by_csname(character_set_filesystem_name,
 
 4053                               MY_CS_PRIMARY, MYF(MY_WME))))
 
 4055   global_system_variables.character_set_filesystem= character_set_filesystem;
 
 4057   if (!(my_default_lc_time_names=
 
 4058         my_locale_by_name(lc_time_names_name)))
 
 4060     sql_print_error(
"Unknown locale: '%s'", lc_time_names_name);
 
 4063   global_system_variables.lc_time_names= my_default_lc_time_names;
 
 4066   if (opt_log && opt_logname && !(log_output_options & LOG_FILE) &&
 
 4067       !(log_output_options & LOG_NONE))
 
 4068     sql_print_warning(
"Although a path was specified for the " 
 4069                       "--general-log-file option, log tables are used. " 
 4070                       "To enable logging to files use the --log-output=file option.");
 
 4072   if (opt_slow_log && opt_slow_logname && !(log_output_options & LOG_FILE)
 
 4073       && !(log_output_options & LOG_NONE))
 
 4074     sql_print_warning(
"Although a path was specified for the " 
 4075                       "--slow-query-log-file option, log tables are used. " 
 4076                       "To enable logging to files use the --log-output=file option.");
 
 4078 #define FIX_LOG_VAR(VAR, ALT)                                   \ 
 4079   if (!VAR || !*VAR)                                            \ 
 4085   FIX_LOG_VAR(opt_logname,
 
 4086               make_default_log_name(logname_path, 
".log"));
 
 4087   FIX_LOG_VAR(opt_slow_logname,
 
 4088               make_default_log_name(slow_logname_path, 
"-slow.log"));
 
 4090 #if defined(ENABLED_DEBUG_SYNC) 
 4092   if (debug_sync_init())
 
 4096 #if (ENABLE_TEMP_POOL) 
 4097   if (use_temp_pool && bitmap_init(&temp_pool,0,1024,1))
 
 4103   if (my_dboptions_cache_init())
 
 4111   DBUG_PRINT(
"info", (
"lower_case_table_names: %d", lower_case_table_names));
 
 4112   lower_case_file_system= test_if_case_insensitive(mysql_real_data_home);
 
 4113   if (!lower_case_table_names && lower_case_file_system == 1)
 
 4115     if (lower_case_table_names_used)
 
 4118   sql_print_warning(
"\ 
 4119 You have forced lower_case_table_names to 0 through a command-line \ 
 4120 option, even though your file system '%s' is case insensitive.  This means \ 
 4121 that you can corrupt a MyISAM table by accessing it with different cases. \ 
 4122 You should consider changing lower_case_table_names to 1 or 2",
 
 4123       mysql_real_data_home);
 
 4128   sql_print_warning(
"Setting lower_case_table_names=2 because file system for %s is case insensitive", mysql_real_data_home);
 
 4129       lower_case_table_names= 2;
 
 4132   else if (lower_case_table_names == 2 &&
 
 4133            !(lower_case_file_system=
 
 4134              (test_if_case_insensitive(mysql_real_data_home) == 1)))
 
 4137       sql_print_warning(
"lower_case_table_names was set to 2, even though your " 
 4138                         "the file system '%s' is case sensitive.  Now setting " 
 4139                         "lower_case_table_names to 0 to avoid future problems.",
 
 4140       mysql_real_data_home);
 
 4141     lower_case_table_names= 0;
 
 4145     lower_case_file_system=
 
 4146       (test_if_case_insensitive(mysql_real_data_home) == 1);
 
 4150   table_alias_charset= (lower_case_table_names ?
 
 4151       &my_charset_utf8_tolower_ci :
 
 4158   if (rpl_filter->build_do_table_hash() ||
 
 4159       rpl_filter->build_ignore_table_hash())
 
 4161     sql_print_error(
"An error occurred while building do_table" 
 4162                     "and ignore_table rules to hush.");
 
 4166   if (ignore_db_dirs_process_additions())
 
 4168     sql_print_error(
"An error occurred while storing ignore_db_dirs to a hash.");
 
 4176 static int init_thread_environment()
 
 4179                    &LOCK_thread_created, MY_MUTEX_INIT_FAST);
 
 4180   mysql_mutex_init(key_LOCK_thread_count, &LOCK_thread_count, MY_MUTEX_INIT_FAST);
 
 4183                    &LOCK_delayed_insert, MY_MUTEX_INIT_FAST);
 
 4185                    &LOCK_delayed_status, MY_MUTEX_INIT_FAST);
 
 4187                    &LOCK_delayed_create, MY_MUTEX_INIT_SLOW);
 
 4189                    &LOCK_manager, MY_MUTEX_INIT_FAST);
 
 4194                    &LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
 
 4196                     &LOCK_system_variables_hash);
 
 4198                    &LOCK_prepared_stmt_count, MY_MUTEX_INIT_FAST);
 
 4200                    &LOCK_sql_slave_skip_counter, MY_MUTEX_INIT_FAST);
 
 4202                    &LOCK_slave_net_timeout, MY_MUTEX_INIT_FAST);
 
 4204                    &LOCK_error_messages, MY_MUTEX_INIT_FAST);
 
 4206                    &LOCK_uuid_generator, MY_MUTEX_INIT_FAST);
 
 4208                    &LOCK_sql_rand, MY_MUTEX_INIT_FAST);
 
 4210                    &LOCK_connection_count, MY_MUTEX_INIT_FAST);
 
 4212                    &LOCK_log_throttle_qni, MY_MUTEX_INIT_FAST);
 
 4215                    &LOCK_des_key_file, MY_MUTEX_INIT_FAST);
 
 4217   openssl_stdlocks= (openssl_lock_t*) OPENSSL_malloc(CRYPTO_num_locks() *
 
 4218                                                      sizeof(openssl_lock_t));
 
 4219   for (
int i= 0; i < CRYPTO_num_locks(); ++
i)
 
 4221   CRYPTO_set_dynlock_create_callback(openssl_dynlock_create);
 
 4222   CRYPTO_set_dynlock_destroy_callback(openssl_dynlock_destroy);
 
 4223   CRYPTO_set_dynlock_lock_callback(openssl_lock);
 
 4224   CRYPTO_set_locking_callback(openssl_lock_function);
 
 4225   CRYPTO_set_id_callback(openssl_id_function);
 
 4233   mysql_cond_init(key_COND_flush_thread_cache, &COND_flush_thread_cache, NULL);
 
 4236                    &LOCK_server_started, MY_MUTEX_INIT_FAST);
 
 4239 #ifdef HAVE_EVENT_SCHEDULER 
 4243   (void) pthread_attr_init(&connection_attrib);
 
 4244   (void) pthread_attr_setdetachstate(&connection_attrib,
 
 4245              PTHREAD_CREATE_DETACHED);
 
 4246   pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM);
 
 4248   if (pthread_key_create(&THR_THD,NULL) ||
 
 4249       pthread_key_create(&THR_MALLOC,NULL))
 
 4251     sql_print_error(
"Can't create thread-keys");
 
 4258 #if defined(HAVE_OPENSSL) && !defined(HAVE_YASSL) 
 4259 static unsigned long openssl_id_function()
 
 4261   return (
unsigned long) pthread_self();
 
 4265 static openssl_lock_t *openssl_dynlock_create(
const char *
file, 
int line)
 
 4267   openssl_lock_t *lock= 
new openssl_lock_t;
 
 4273 static void openssl_dynlock_destroy(openssl_lock_t *lock, 
const char *
file,
 
 4281 static void openssl_lock_function(
int mode, 
int n, 
const char *
file, 
int line)
 
 4283   if (n < 0 || n > CRYPTO_num_locks())
 
 4286     sql_print_error(
"Fatal: OpenSSL interface problem (n = %d)", n);
 
 4289   openssl_lock(mode, &openssl_stdlocks[n], file, line);
 
 4293 static void openssl_lock(
int mode, openssl_lock_t *lock, 
const char *file,
 
 4300   case CRYPTO_LOCK|CRYPTO_READ:
 
 4304   case CRYPTO_LOCK|CRYPTO_WRITE:
 
 4305     what = 
"write lock";
 
 4308   case CRYPTO_UNLOCK|CRYPTO_READ:
 
 4309   case CRYPTO_UNLOCK|CRYPTO_WRITE:
 
 4315     sql_print_error(
"Fatal: OpenSSL interface problem (mode=0x%x)", mode);
 
 4320     sql_print_error(
"Fatal: can't %s OpenSSL lock", what);
 
 4327 static int init_ssl()
 
 4331   CRYPTO_malloc_init();
 
 4334 #ifndef EMBEDDED_LIBRARY 
 4337     enum enum_ssl_init_error error= SSL_INITERR_NOERROR;
 
 4340     ssl_acceptor_fd= new_VioSSLAcceptorFd(opt_ssl_key, opt_ssl_cert,
 
 4341                                           opt_ssl_ca, opt_ssl_capath,
 
 4342                                           opt_ssl_cipher, &error,
 
 4343                                           opt_ssl_crl, opt_ssl_crlpath);
 
 4344     DBUG_PRINT(
"info",(
"ssl_acceptor_fd: 0x%lx", (
long) ssl_acceptor_fd));
 
 4345     ERR_remove_state(0);
 
 4346     if (!ssl_acceptor_fd)
 
 4348       sql_print_warning(
"Failed to setup SSL");
 
 4349       sql_print_warning(
"SSL error: %s", sslGetErrString(error));
 
 4351       have_ssl= SHOW_OPTION_DISABLED;
 
 4356     have_ssl= SHOW_OPTION_DISABLED;
 
 4359   have_ssl= SHOW_OPTION_DISABLED;
 
 4362     load_des_key_file(des_key_file);
 
 4364   if (init_rsa_keys())
 
 4372 static void end_ssl()
 
 4375 #ifndef EMBEDDED_LIBRARY 
 4376   if (ssl_acceptor_fd)
 
 4378     free_vio_ssl_acceptor_fd(ssl_acceptor_fd);
 
 4393 static int generate_server_uuid()
 
 4404     sql_print_error(
"Failed to generate a server UUID because it is failed" 
 4405                     " to allocate the THD.");
 
 4408   thd->thread_stack= (
char*) &thd;
 
 4409   thd->store_globals();
 
 4412   func_uuid->fixed= 1;
 
 4413   func_uuid->val_str(&uuid);
 
 4416   my_pthread_setspecific_ptr(THR_THD,  0);
 
 4418   strncpy(server_uuid, uuid.c_ptr(), UUID_LENGTH);
 
 4419   server_uuid[UUID_LENGTH]= 
'\0';
 
 4431 int flush_auto_options(
const char* fname)
 
 4437   if ((fd= my_open((
const char *)fname, O_CREAT|O_RDWR, MYF(MY_WME))) < 0)
 
 4439     sql_print_error(
"Failed to create file(file: '%s', errno %d)", fname, my_errno);
 
 4443   if (init_io_cache(&io_cache, fd, IO_SIZE*2, WRITE_CACHE, 0L, 0, MYF(MY_WME)))
 
 4445     sql_print_error(
"Failed to create a cache on (file: %s', errno %d)", fname, my_errno);
 
 4446     my_close(fd, MYF(MY_WME));
 
 4450   my_b_seek(&io_cache, 0L);
 
 4451   my_b_printf(&io_cache, 
"%s\n", 
"[auto]");
 
 4452   my_b_printf(&io_cache, 
"server-uuid=%s\n", server_uuid);
 
 4454   if (flush_io_cache(&io_cache) || my_sync(fd, MYF(MY_WME)))
 
 4457   my_close(fd, MYF(MY_WME));
 
 4458   end_io_cache(&io_cache);
 
 4477 static int init_server_auto_options()
 
 4480   char fname[FN_REFLEN];
 
 4481   char *
name= (
char *)
"auto";
 
 4482   const char *groups[]= {
"auto", NULL};
 
 4485     {
"server-uuid", 0, 
"", &uuid, &uuid,
 
 4486       0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 4487     {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
 4490   DBUG_ENTER(
"init_server_auto_options");
 
 4492   if (NULL == fn_format(fname, 
"auto.cnf", mysql_data_home, 
"",
 
 4493                         MY_UNPACK_FILENAME | MY_SAFE_PATH))
 
 4500   if (my_load_defaults(fname, groups, &argc, &argv, NULL))
 
 4507   char **old_argv= argv;
 
 4508   if (handle_options(&argc, &argv, auto_options, mysqld_get_one_option))
 
 4511   DBUG_PRINT(
"info", (
"uuid=%p=%s server_uuid=%s", uuid, uuid, server_uuid));
 
 4516       sql_print_error(
"The server_uuid stored in auto.cnf file is not a valid UUID.");
 
 4519     strcpy(server_uuid, uuid);
 
 4523     DBUG_PRINT(
"info", (
"generating server_uuid"));
 
 4526     if (generate_server_uuid())
 
 4528     DBUG_PRINT(
"info", (
"generated server_uuid=%s", server_uuid));
 
 4529     sql_print_warning(
"No existing UUID has been found, so we assume that this" 
 4530                       " is the first time that this server has been started." 
 4531                       " Generating a new UUID: %s.",
 
 4538   free_defaults(old_argv);
 
 4541     DBUG_RETURN(flush_auto_options(fname));
 
 4544   free_defaults(argv);
 
 4550 initialize_storage_engine(
char *se_name, 
const char *se_kind,
 
 4553   LEX_STRING name= { se_name, strlen(se_name) };
 
 4560     sql_print_error(
"Unknown/unsupported storage engine: %s", se_name);
 
 4563   if (!ha_storage_engine_is_enabled(hton))
 
 4567       sql_print_error(
"Default%s storage engine (%s) is not available",
 
 4571     DBUG_ASSERT(*dest_plugin);
 
 4579     plugin_unlock(0, *dest_plugin);
 
 4580     *dest_plugin= plugin;
 
 4586 static int init_server_components()
 
 4588   DBUG_ENTER(
"init_server_components");
 
 4594   if (table_def_init() | hostname_cache_init())
 
 4597   query_cache_set_min_res_unit(query_cache_min_res_unit);
 
 4599   query_cache_resize(query_cache_size);
 
 4600   randominit(&sql_rand,(ulong) server_start_time,(ulong) server_start_time/2);
 
 4603 #ifdef HAVE_REPLICATION 
 4614   if (opt_error_log && !opt_help)
 
 4616     if (!log_error_file_ptr[0])
 
 4617       fn_format(log_error_file, pidfile_name, mysql_data_home, 
".err",
 
 4620       fn_format(log_error_file, log_error_file_ptr, mysql_data_home, 
".err",
 
 4621                 MY_UNPACK_FILENAME | MY_SAFE_PATH);
 
 4626     log_error_file_ptr= log_error_file;
 
 4627     if (!log_error_file[0])
 
 4632 #ifndef EMBEDDED_LIBRARY 
 4633       res= reopen_fstreams(log_error_file, stdout, stderr);
 
 4635       res= reopen_fstreams(log_error_file, NULL, stderr);
 
 4639         setbuf(stderr, NULL);
 
 4643   proc_info_hook= set_thd_stage_info;
 
 4645 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE 
 4653   buffered_logs.
print();
 
 4654   buffered_logs.cleanup();
 
 4662   my_charset_error_reporter= charset_error_reporter;
 
 4664   if (xid_cache_init())
 
 4666     sql_print_error(
"Out of memory");
 
 4674   if (delegates_init())
 
 4678   if (opt_log_slave_updates && !opt_bin_log)
 
 4680     sql_print_warning(
"You need to use --log-bin to make " 
 4681                     "--log-slave-updates work.");
 
 4683   if (binlog_format_used && !opt_bin_log)
 
 4684     sql_print_warning(
"You need to use --log-bin to make " 
 4685                       "--binlog-format work.");
 
 4689               array_elements(binlog_format_names)-1);
 
 4691 #ifdef HAVE_REPLICATION 
 4692   if (opt_log_slave_updates && replicate_same_server_id)
 
 4696       sql_print_error(
"using --replicate-same-server-id in conjunction with \ 
 4697 --log-slave-updates is impossible, it would lead to infinite loops in this \ 
 4702       sql_print_warning(
"using --replicate-same-server-id in conjunction with \ 
 4703 --log-slave-updates would lead to infinite loops in this server. However this \ 
 4704 will be ignored as the --log-bin option is not defined.");
 
 4708   opt_server_id_mask = ~ulong(0);
 
 4709 #ifdef HAVE_REPLICATION 
 4710   opt_server_id_mask = (opt_server_id_bits == 32)?
 
 4711     ~ ulong(0) : (1 << opt_server_id_bits) -1;
 
 4712   if (server_id != (server_id & opt_server_id_mask))
 
 4714     sql_print_error(
"server-id configured is too large to represent with" 
 4715                     "server-id-bits configured.");
 
 4724     if (opt_bin_logname &&
 
 4725         opt_bin_logname[strlen(opt_bin_logname) - 1] == FN_LIBCHAR)
 
 4727       sql_print_error(
"Path '%s' is a directory name, please specify \ 
 4728 a file name for --log-bin option", opt_bin_logname);
 
 4734     if (opt_binlog_index_name &&
 
 4735         opt_binlog_index_name[strlen(opt_binlog_index_name) - 1]
 
 4738       sql_print_error(
"Path '%s' is a directory name, please specify \ 
 4739 a file name for --log-bin-index option", opt_binlog_index_name);
 
 4743     char buf[FN_REFLEN];
 
 4745     ln= mysql_bin_log.
generate_name(opt_bin_logname, 
"-bin", 1, buf);
 
 4746     if (!opt_bin_logname && !opt_binlog_index_name)
 
 4755       sql_print_warning(
"No argument was provided to --log-bin, and " 
 4756                         "--log-bin-index was not used; so replication " 
 4757                         "may break when this MySQL server acts as a " 
 4758                         "master and has his hostname changed!! Please " 
 4759                         "use '--log-bin=%s' to avoid this problem.", ln);
 
 4763       my_free(opt_bin_logname);
 
 4764       opt_bin_logname=my_strdup(buf, MYF(0));
 
 4766     if (mysql_bin_log.open_index_file(opt_binlog_index_name, ln, TRUE))
 
 4775       rpl_make_log_name(opt_bin_logname, pidfile_name,
 
 4776                         opt_bin_logname ? 
"" : 
"-bin");
 
 4778       rpl_make_log_name(opt_binlog_index_name, log_bin_basename, 
".index");
 
 4779     if (log_bin_basename == NULL || log_bin_index == NULL)
 
 4781       sql_print_error(
"Unable to create replication path names:" 
 4782                       " out of memory or path names too long" 
 4783                       " (path name exceeds " STRINGIFY_ARG(FN_REFLEN)
 
 4784                       " or file name exceeds " STRINGIFY_ARG(FN_LEN) 
").");
 
 4789 #ifndef EMBEDDED_LIBRARY 
 4791              (
"opt_bin_logname: %s, opt_relay_logname: %s, pidfile_name: %s",
 
 4792               opt_bin_logname, opt_relay_logname, pidfile_name));
 
 4793   if (opt_relay_logname)
 
 4796       rpl_make_log_name(opt_relay_logname, pidfile_name,
 
 4797                         opt_relay_logname ? 
"" : 
"-relay-bin");
 
 4799       rpl_make_log_name(opt_relaylog_index_name, relay_log_basename, 
".index");
 
 4800     if (relay_log_basename == NULL || relay_log_index == NULL)
 
 4802       sql_print_error(
"Unable to create replication path names:" 
 4803                       " out of memory or path names too long" 
 4804                       " (path name exceeds " STRINGIFY_ARG(FN_REFLEN)
 
 4805                       " or file name exceeds " STRINGIFY_ARG(FN_LEN) 
").");
 
 4818   if (opt_ignore_builtin_innodb)
 
 4819     sql_print_warning(
"ignore-builtin-innodb is ignored " 
 4820                       "and will be removed in future releases.");
 
 4821   if (gtid_server_init())
 
 4823     sql_print_error(
"Failed to initialize GTID structures.");
 
 4827   if (plugin_init(&remaining_argc, remaining_argv,
 
 4828                   (opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) |
 
 4829                   (opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0)))
 
 4831     sql_print_error(
"Failed to initialize plugins.");
 
 4834   plugins_are_initialized= TRUE;  
 
 4837   if (remaining_argc > 1)
 
 4842       {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
 4848     my_getopt_skip_unknown= 0;
 
 4850     if ((ho_error= handle_options(&remaining_argc, &remaining_argv, no_opts,
 
 4851                                   mysqld_get_one_option)))
 
 4852       unireg_abort(ho_error);
 
 4856     my_getopt_skip_unknown= TRUE;
 
 4858     if (remaining_argc > 1)
 
 4860       fprintf(stderr, 
"%s: Too many arguments (first extra is '%s').\n" 
 4861               "Use --verbose --help to get a list of available options\n",
 
 4862               my_progname, remaining_argv[1]);
 
 4871   if (!DEFAULT_ERRMSGS[0][0])
 
 4877     sql_print_error(
"Can't init databases");
 
 4881 #ifdef WITH_CSV_STORAGE_ENGINE 
 4883     log_output_options= LOG_FILE;
 
 4885     logger.init_log_tables();
 
 4887   if (log_output_options & LOG_NONE)
 
 4893     if ((log_output_options & LOG_NONE) && (log_output_options & ~LOG_NONE))
 
 4894       sql_print_warning(
"There were other values specified to " 
 4895                         "log-output besides NONE. Disabling slow " 
 4896                         "and general logs anyway.");
 
 4897     logger.set_handlers(LOG_FILE, LOG_NONE, LOG_NONE);
 
 4902     LEX_STRING csv_name={C_STRING_WITH_LEN(
"csv")};
 
 4903     if (!plugin_is_ready(&csv_name, MYSQL_STORAGE_ENGINE_PLUGIN))
 
 4906       sql_print_error(
"CSV engine is not present, falling back to the " 
 4908       log_output_options= (log_output_options & ~LOG_TABLE) | LOG_FILE;
 
 4912     logger.set_handlers(LOG_FILE, opt_slow_log ? log_output_options:LOG_NONE,
 
 4913                         opt_log ? log_output_options:LOG_NONE);
 
 4916   logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_FILE:LOG_NONE,
 
 4917                       opt_log ? LOG_FILE:LOG_NONE);
 
 4923   if (initialize_storage_engine(default_storage_engine, 
"",
 
 4924                                 &global_system_variables.table_plugin))
 
 4926   if (initialize_storage_engine(default_tmp_storage_engine, 
" temp",
 
 4927                                 &global_system_variables.temp_table_plugin))
 
 4930   if (total_ha_2pc > 1 || (1 == total_ha_2pc && opt_bin_log))
 
 4933       tc_log= &mysql_bin_log;
 
 4935       tc_log= &tc_log_mmap;
 
 4938     tc_log= &tc_log_dummy;
 
 4940   if (tc_log->open(opt_bin_log ? opt_bin_logname : opt_tc_log_file))
 
 4942     sql_print_error(
"Can't init tc log");
 
 4951   if (gtid_mode >= 1 && opt_bootstrap)
 
 4953     sql_print_warning(
"Bootstrap mode disables GTIDs. Bootstrap mode " 
 4954     "should only be used by mysql_install_db which initializes the MySQL " 
 4955     "data directory and creates system tables.");
 
 4958   if (gtid_mode >= 1 && !(opt_bin_log && opt_log_slave_updates))
 
 4960     sql_print_error(
"--gtid-mode=ON or UPGRADE_STEP_1 or UPGRADE_STEP_2 requires --log-bin and --log-slave-updates");
 
 4963   if (gtid_mode >= 2 && !enforce_gtid_consistency)
 
 4965     sql_print_error(
"--gtid-mode=ON or UPGRADE_STEP_1 requires --enforce-gtid-consistency");
 
 4968   if (gtid_mode == 1 || gtid_mode == 2)
 
 4970     sql_print_error(
"--gtid-mode=UPGRADE_STEP_1 or --gtid-mode=UPGRADE_STEP_2 are not yet supported");
 
 4981     mysql_bin_log.set_previous_gtid_set(
 
 4984                                   WRITE_CACHE, max_binlog_size, 
false,
 
 4991 #ifdef HAVE_REPLICATION 
 4992   if (opt_bin_log && expire_logs_days)
 
 4994     time_t purge_time= server_start_time - expire_logs_days*24*60*60;
 
 4995     if (purge_time >= 0)
 
 4996       mysql_bin_log.purge_logs_before_date(purge_time, 
true);
 
 5003 #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) && !defined(EMBEDDED_LIBRARY) 
 5004   if (locked_in_memory && !getuid())
 
 5006     if (setreuid((uid_t)-1, 0) == -1)
 
 5008       sql_perror(
"setreuid");
 
 5011     if (mlockall(MCL_CURRENT))
 
 5014   sql_print_warning(
"Failed to lock memory. Errno: %d\n",errno);
 
 5015       locked_in_memory= 0;
 
 5018       set_user(mysqld_user, user_info);
 
 5024   ft_init_stopwords();
 
 5026   init_max_user_conn();
 
 5027   init_update_queries();
 
 5032 #ifndef EMBEDDED_LIBRARY 
 5034 static void create_shutdown_thread()
 
 5037   hEventShutdown=CreateEvent(0, FALSE, FALSE, shutdown_event_name);
 
 5041                                   &hThread, &connection_attrib,
 
 5042                                   handle_shutdown, 0)))
 
 5043     sql_print_warning(
"Can't create thread to handle shutdown requests" 
 5044                       " (errno= %d)", error);
 
 5047   Service.SetShutdownEvent(hEventShutdown);
 
 5054 #if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) 
 5055 static void handle_connections_methods()
 
 5059   DBUG_ENTER(
"handle_connections_methods");
 
 5060   if (hPipe == INVALID_HANDLE_VALUE &&
 
 5061       (!have_tcpip || opt_disable_networking) &&
 
 5062       !opt_enable_shared_memory)
 
 5064     sql_print_error(
"TCP/IP, --shared-memory, or --named-pipe should be configured on NT OS");
 
 5071   if (hPipe != INVALID_HANDLE_VALUE)
 
 5075                                     &hThread, &connection_attrib,
 
 5076                                     handle_connections_namedpipes, 0)))
 
 5078       sql_print_warning(
"Can't create thread to handle named pipes" 
 5079                         " (errno= %d)", error);
 
 5083   if (have_tcpip && !opt_disable_networking)
 
 5087                                     &hThread, &connection_attrib,
 
 5088                                     handle_connections_sockets_thread, 0)))
 
 5090       sql_print_warning(
"Can't create thread to handle TCP/IP",
 
 5091                         " (errno= %d)", error);
 
 5096   if (opt_enable_shared_memory)
 
 5100                                     &hThread, &connection_attrib,
 
 5101                                     handle_connections_shared_memory, 0)))
 
 5103       sql_print_warning(
"Can't create thread to handle shared memory",
 
 5104                         " (errno= %d)", error);
 
 5110   while (handler_count > 0)
 
 5116 void decrement_handler_count()
 
 5125 #define decrement_handler_count() 
 5129 #ifndef EMBEDDED_LIBRARY 
 5136 static void test_lc_time_sz()
 
 5138   DBUG_ENTER(
"test_lc_time_sz");
 
 5139   for (
MY_LOCALE **loc= my_locales; *loc; loc++)
 
 5141     uint max_month_len= 0;
 
 5142     uint max_day_len = 0;
 
 5143     for (
const char **month= (*loc)->month_names->type_names; *month; month++)
 
 5145       set_if_bigger(max_month_len,
 
 5146                     my_numchars_mb(&my_charset_utf8_general_ci,
 
 5147                                    *month, *month + strlen(*month)));
 
 5149     for (
const char **day= (*loc)->day_names->type_names; *day; day++)
 
 5151       set_if_bigger(max_day_len,
 
 5152                     my_numchars_mb(&my_charset_utf8_general_ci,
 
 5153                                    *day, *day + strlen(*day)));
 
 5155     if ((*loc)->max_month_name_length != max_month_len ||
 
 5156         (*loc)->max_day_name_length != max_day_len)
 
 5158       DBUG_PRINT(
"Wrong max day name(or month name) length for locale:",
 
 5159                  (
"%s", (*loc)->name));
 
 5168 int win_main(
int argc, 
char **argv)
 
 5170 int mysqld_main(
int argc, 
char **argv)
 
 5177   my_progname= argv[0];
 
 5179   ld_assume_kernel_is_set= (getenv(
"LD_ASSUME_KERNEL") != 0);
 
 5185     fprintf(stderr, 
"my_init() failed.");
 
 5192   my_getopt_use_args_separator= TRUE;
 
 5193   if (load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv))
 
 5195   my_getopt_use_args_separator= FALSE;
 
 5196   defaults_argc= argc;
 
 5197   defaults_argv= argv;
 
 5198   remaining_argc= argc;
 
 5199   remaining_argv= argv;
 
 5202   system_charset_info= &my_charset_utf8_general_ci;
 
 5204   init_sql_statement_names();
 
 5209 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE 
 5216   ho_error= handle_early_options();
 
 5219     ulong requested_open_files;
 
 5220     adjust_related_options(&requested_open_files);
 
 5222 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE 
 5233         if (PSI_hook == NULL)
 
 5236           buffered_logs.
buffer(WARNING_LEVEL,
 
 5237                                "Performance schema disabled (reason: init failed).");
 
 5254 #ifdef HAVE_PSI_INTERFACE 
 5262     if (likely(psi_server != NULL))
 
 5264       set_psi_server(psi_server);
 
 5271       init_server_psi_keys();
 
 5273       PSI_thread *psi= PSI_THREAD_CALL(new_thread)(key_thread_main, NULL, 0);
 
 5274       PSI_THREAD_CALL(set_thread)(psi);
 
 5281       my_thread_global_reinit();
 
 5286   init_error_log_mutex();
 
 5289 #if defined(SIGUSR2) 
 5290   thr_kill_signal= thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
 
 5292   thr_kill_signal= SIGINT;
 
 5296   mysql_audit_initialize();
 
 5315     buffered_logs.
print();
 
 5316     buffered_logs.cleanup();
 
 5324 #ifdef _CUSTOMSTARTUPCONFIG_ 
 5325   if (_cust_check_startup())
 
 5327     / * _cust_check_startup will report startup failure error * /
 
 5332   if (init_common_variables())
 
 5338   int retval= pthread_attr_getguardsize(&connection_attrib, &guardize);
 
 5339   DBUG_ASSERT(retval == 0);
 
 5341     guardize= my_thread_stack_size;
 
 5343 #if defined(__ia64__) || defined(__ia64) 
 5348   guardize= my_thread_stack_size;
 
 5351   pthread_attr_setstacksize(&connection_attrib,
 
 5352                             my_thread_stack_size + guardize);
 
 5354 #ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE 
 5357     size_t stack_size= 0;
 
 5358     pthread_attr_getstacksize(&connection_attrib, &stack_size);
 
 5361     if (stack_size && stack_size < (my_thread_stack_size + guardize))
 
 5364         sql_print_warning(
"Asked for %lu thread stack, but got %ld",
 
 5365                           my_thread_stack_size + guardize, (
long) stack_size);
 
 5366 #if defined(__ia64__) || defined(__ia64) 
 5367       my_thread_stack_size= stack_size / 2;
 
 5369       my_thread_stack_size= stack_size - guardize;
 
 5375   (void) thr_setconcurrency(concurrency); 
 
 5377   select_thread=pthread_self();
 
 5378   select_thread_in_use=1;
 
 5381   libwrapName= my_progname+dirname_length(my_progname);
 
 5382   openlog(libwrapName, LOG_PID, LOG_AUTH);
 
 5393   check_data_home(mysql_real_data_home);
 
 5394   if (my_setwd(mysql_real_data_home,MYF(MY_WME)) && !opt_help)
 
 5397   if ((user_info= check_user(mysqld_user)))
 
 5399 #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) 
 5400     if (locked_in_memory) 
 
 5401       set_effective_user(user_info);
 
 5404       set_user(mysqld_user, user_info);
 
 5407   if (opt_bin_log && server_id == 0)
 
 5411     sql_print_warning(
"You have enabled the binary log, but you haven't set " 
 5412                       "server-id to a non-zero value: we force server id to 1; " 
 5413                       "updates will be logged to the binary log, but " 
 5414                       "connections from slaves will not be accepted.");
 
 5422 #if defined(_WIN32) && !defined(EMBEDDED_LIBRARY) 
 5426   if (init_server_components())
 
 5435     if (init_server_auto_options())
 
 5437       sql_print_error(
"Initialzation of the server's UUID failed because it could" 
 5438                       " not be read from the auto.cnf file. If this is a new" 
 5439                       " server, the initialization failed because it was not" 
 5440                       " possible to generate a new UUID.");
 
 5454       global_sid_lock->
rdlock();
 
 5455       int ret= gtid_state->
init();
 
 5456       global_sid_lock->
unlock();
 
 5463             opt_master_verify_checksum,
 
 5477         global_sid_lock->
wrlock();
 
 5479         if (gtid_mode > 1 || !logged_gtids->
is_empty())
 
 5482           global_sid_lock->
unlock();
 
 5484           prev_gtids_ev.checksum_alg= binlog_checksum_options;
 
 5486           if (prev_gtids_ev.write(mysql_bin_log.get_log_file()))
 
 5488           mysql_bin_log.add_bytes_written(prev_gtids_ev.data_written);
 
 5490           if (flush_io_cache(mysql_bin_log.get_log_file()) ||
 
 5495           global_sid_lock->
unlock();
 
 5507     if (reopen_fstreams(log_error_file, stdout, stderr))
 
 5509     setbuf(stderr, NULL);
 
 5517   my_str_malloc= &my_str_malloc_mysqld;
 
 5518   my_str_free= &my_str_free_mysqld;
 
 5519   my_str_realloc= &my_str_realloc_mysqld;
 
 5525   error_handler_hook= my_message_sql;
 
 5526   start_signal_handler();       
 
 5527   sql_print_warning_hook = sql_print_warning;
 
 5529   if (mysql_rm_tmp_tables() || acl_init(opt_noacl) ||
 
 5530       my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
 
 5533     select_thread_in_use=0;
 
 5535     (void) pthread_kill(signal_thread, MYSQL_KILL_SIGNAL);
 
 5537     delete_pid_file(MYF(MY_WME));
 
 5539     if (mysql_socket_getfd(unix_sock) != INVALID_SOCKET)
 
 5540       unlink(mysqld_unix_port);
 
 5545     (void) grant_init();
 
 5560     opt_skip_slave_start= 1;
 
 5565   binlog_unsafe_map_init();
 
 5571     set_slave_skip_errors(&opt_slave_skip_errors);
 
 5580 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE 
 5588   if (! opt_bootstrap)
 
 5592   initialize_information_schema_acl();
 
 5594   execute_ddl_log_recovery();
 
 5601     select_thread_in_use= 0;                    
 
 5604     mysqld_server_started= 1;
 
 5608     bootstrap(mysql_stdin);
 
 5609     unireg_abort(bootstrap_error ? 1 : 0);
 
 5611   if (opt_init_file && *opt_init_file)
 
 5613     if (read_init_file(opt_init_file))
 
 5617   create_shutdown_thread();
 
 5618   start_handle_manager();
 
 5620   sql_print_information(ER_DEFAULT(ER_STARTUP),my_progname,server_version,
 
 5621                         ((mysql_socket_getfd(unix_sock) == INVALID_SOCKET) ? (
char*) 
"" 
 5622                                                        : mysqld_unix_port),
 
 5624                          MYSQL_COMPILATION_COMMENT);
 
 5625 #if defined(_WIN32) && !defined(EMBEDDED_LIBRARY) 
 5626   Service.SetRunning();
 
 5632   mysqld_server_started= 1;
 
 5636 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE 
 5638   if (ndb_wait_setup_func && ndb_wait_setup_func(opt_ndb_wait_setup))
 
 5640     sql_print_warning(
"NDB : Tables not available after %lu seconds." 
 5641                       "  Consider increasing --ndb-wait-setup value",
 
 5642                       opt_ndb_wait_setup);
 
 5646 #if defined(_WIN32) || defined(HAVE_SMEM) 
 5647   handle_connections_methods();
 
 5649   handle_connections_sockets();
 
 5654   DBUG_PRINT(
"quit",(
"Exiting main thread"));
 
 5658   sql_print_error(
"Before Lock_thread_count");
 
 5661   DBUG_PRINT(
"quit", (
"Got thread_count mutex"));
 
 5662   select_thread_in_use=0;     
 
 5666   sql_print_error(
"After lock_thread_count");
 
 5670 #ifdef HAVE_PSI_THREAD_INTERFACE 
 5675   PSI_THREAD_CALL(delete_current_thread)();
 
 5680   while (!ready_to_exit)
 
 5684 #if defined(__WIN__) && !defined(EMBEDDED_LIBRARY) 
 5685   if (Service.IsNT() && start_mode)
 
 5689     Service.SetShutdownEvent(0);
 
 5691       CloseHandle(hEventShutdown);
 
 5706 #if defined(__WIN__) && !defined(EMBEDDED_LIBRARY) 
 5707 int mysql_service(
void *p)
 
 5709   if (my_thread_init())
 
 5713     win_main(opt_argc, opt_argv);
 
 5715     win_main(Service.my_argc, Service.my_argv);
 
 5724 static char *add_quoted_string(
char *
to, 
const char *from, 
char *to_end)
 
 5726   uint length= (uint) (to_end-to);
 
 5728   if (!strchr(from, 
' '))
 
 5729     return strmake(to, from, length-1);
 
 5730   return strxnmov(to, length-1, 
"\"", from, 
"\"", NullS);
 
 5750 default_service_handling(
char **argv,
 
 5751        const char *servicename,
 
 5752        const char *displayname,
 
 5753        const char *file_path,
 
 5754        const char *extra_opt,
 
 5755        const char *account_name)
 
 5757   char path_and_service[FN_REFLEN+FN_REFLEN+32], *pos, *end;
 
 5758   const char *opt_delim;
 
 5759   end= path_and_service + 
sizeof(path_and_service)-3;
 
 5762   pos= add_quoted_string(path_and_service, file_path, end);
 
 5771     if (opt_delim= strchr(extra_opt, 
'='))
 
 5773       size_t length= ++opt_delim - extra_opt;
 
 5774       pos= strnmov(pos, extra_opt, length);
 
 5777       opt_delim= extra_opt;
 
 5779     pos= add_quoted_string(pos, opt_delim, end);
 
 5783   (void) add_quoted_string(pos, servicename, end);
 
 5785   if (Service.got_service_option(argv, 
"install"))
 
 5787     Service.
Install(1, servicename, displayname, path_and_service,
 
 5791   if (Service.got_service_option(argv, 
"install-manual"))
 
 5793     Service.
Install(0, servicename, displayname, path_and_service,
 
 5797   if (Service.got_service_option(argv, 
"remove"))
 
 5799     Service.
Remove(servicename);
 
 5806 int mysqld_main(
int argc, 
char **argv)
 
 5813   int10_to_str((
int) GetCurrentProcessId(),strmov(shutdown_event_name,
 
 5814                                                   "MySQLShutdown"), 10);
 
 5817   system_charset_info= &my_charset_utf8_general_ci;
 
 5821     fprintf(stderr, 
"my_init() failed.");
 
 5825   if (Service.GetOS())  
 
 5827     char file_path[FN_REFLEN];
 
 5828     my_path(file_path, argv[0], 
"");          
 
 5829     fn_format(file_path,argv[0],file_path,
"",
 
 5830         MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS);
 
 5834       if (!default_service_handling(argv, MYSQL_SERVICENAME, MYSQL_SERVICENAME,
 
 5835            file_path, 
"", NULL))
 
 5837       if (Service.IsService(argv[1]))        
 
 5845   if (my_strcasecmp(system_charset_info, argv[1],
"mysql"))
 
 5846     load_default_groups[load_default_groups_sz-2]= argv[1];
 
 5848         Service.
Init(argv[1], mysql_service);
 
 5854       if (!default_service_handling(argv, argv[2], argv[2], file_path, 
"",
 
 5857       if (Service.IsService(argv[2]))
 
 5867   if (my_strcasecmp(system_charset_info, argv[2],
"mysql"))
 
 5868     load_default_groups[load_default_groups_sz-2]= argv[2];
 
 5869   Service.
Init(argv[2], mysql_service);
 
 5873     else if (argc == 4 || argc == 5)
 
 5882       const char *extra_opt= NullS;
 
 5883       const char *account_name = NullS;
 
 5885       for (index = 3; index < argc; index++)
 
 5887         if (!strcmp(argv[index], 
"--local-service"))
 
 5888           account_name= 
"NT AUTHORITY\\LocalService";
 
 5890           extra_opt= argv[
index];
 
 5893       if (argc == 4 || account_name)
 
 5894         if (!default_service_handling(argv, argv[2], argv[2], file_path,
 
 5895                                       extra_opt, account_name))
 
 5898     else if (argc == 1 && Service.IsService(MYSQL_SERVICENAME))
 
 5902       Service.
Init(MYSQL_SERVICENAME, mysql_service);
 
 5907   Service.my_argc=argc;
 
 5908   Service.my_argv=argv;
 
 5909   mysql_service(NULL);
 
 5922   DBUG_ENTER(
"bootstrap");
 
 5927   thd->max_client_packet_length= thd->net.max_packet;
 
 5928   thd->security_ctx->master_access= ~(ulong)0;
 
 5929   thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
 
 5933   bootstrap_file=
file;
 
 5934 #ifndef EMBEDDED_LIBRARY      // TODO:  Enable this 
 5937                                   &thd->real_id, &connection_attrib,
 
 5941     sql_print_warning(
"Can't create thread to handle bootstrap (errno= %d)",
 
 5948   while (in_bootstrap)
 
 5951     DBUG_PRINT(
"quit", (
"One thread died (count=%u)", get_thread_count()));
 
 5956   do_handle_bootstrap(thd);
 
 5963 static bool read_init_file(
char *file_name)
 
 5966   DBUG_ENTER(
"read_init_file");
 
 5967   DBUG_PRINT(
"enter",(
"name: %s",file_name));
 
 5969   sql_print_information(
"Execution of init_file \'%s\' started.", file_name);
 
 5972                                O_RDONLY, MYF(MY_WME))))
 
 5977   sql_print_information(
"Execution of init_file \'%s\' ended.", file_name);
 
 5986 void inc_thread_created(
void)
 
 5993 #ifndef EMBEDDED_LIBRARY 
 6005 void handle_connection_in_main_thread(THD *thd)
 
 6008   max_blocked_pthreads= 0;      
 
 6009   add_global_thread(thd);
 
 6011   thd->start_utime= my_micro_time();
 
 6012   do_handle_one_connection(thd);
 
 6020 void create_thread_to_handle_connection(THD *thd)
 
 6023   if (blocked_pthread_count >  wake_pthread)
 
 6026     DBUG_PRINT(
"info", (
"waiting_thd_list->push %p", thd));
 
 6027     waiting_thd_list->push_back(thd);
 
 6033     char error_message_buff[MYSQL_ERRMSG_SIZE];
 
 6036     inc_thread_created();
 
 6037     DBUG_PRINT(
"info",((
"creating thread %lu"), thd->thread_id));
 
 6038     thd->prior_thr_create_utime= thd->start_utime= my_micro_time();
 
 6040                                     &thd->real_id, &connection_attrib,
 
 6041                                     handle_one_connection,
 
 6046                  (
"Can't create thread to handle request (error %d)",
 
 6048       if (!err_log_throttle.log(thd))
 
 6049         sql_print_error(
"Can't create thread to handle request (errno= %d)",
 
 6051       thd->killed= THD::KILL_CONNECTION;      
 
 6058       statistic_increment(aborted_connects,&LOCK_status);
 
 6059       statistic_increment(connection_errors_internal, &LOCK_status);
 
 6061       my_snprintf(error_message_buff, 
sizeof(error_message_buff),
 
 6062                   ER_THD(thd, ER_CANT_CREATE_THREAD), error);
 
 6063       net_send_error(thd, ER_CANT_CREATE_THREAD, error_message_buff, NULL);
 
 6064       close_connection(thd);
 
 6069     add_global_thread(thd);
 
 6072   DBUG_PRINT(
"info",(
"Thread created"));
 
 6088 static void create_new_thread(THD *thd)
 
 6090   DBUG_ENTER(
"create_new_thread");
 
 6099   if (connection_count >= max_connections + 1 || abort_loop)
 
 6103     DBUG_PRINT(
"error",(
"Too many connections"));
 
 6116     close_connection(thd, ER_CON_COUNT_ERROR);
 
 6118     statistic_increment(connection_errors_max_connection, &LOCK_status);
 
 6124   if (connection_count > max_used_connections)
 
 6125     max_used_connections= connection_count;
 
 6138   thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
 
 6140   MYSQL_CALLBACK(thread_scheduler, add_connection, (thd));
 
 6147 #ifdef SIGNALS_DONT_BREAK_READ 
 6148 inline void kill_broken_server()
 
 6151   if (mysql_get_fd(unix_sock) == INVALID_SOCKET ||
 
 6152       (!opt_disable_networking && mysql_socket_getfd(ip_sock) == INVALID_SOCKET))
 
 6154     select_thread_in_use = 0;
 
 6156     kill_server((
void*) MYSQL_KILL_SIGNAL);
 
 6159 #define MAYBE_BROKEN_SYSCALL kill_broken_server(); 
 6161 #define MAYBE_BROKEN_SYSCALL 
 6166 #ifndef EMBEDDED_LIBRARY 
 6168 void handle_connections_sockets()
 
 6174   struct sockaddr_storage cAddr;
 
 6175   int ip_flags=0,socket_flags=0,
flags=0,retval;
 
 6178   int socket_count= 0;
 
 6179   struct pollfd fds[2]; 
 
 6182   fd_set readFDs,clientFDs;
 
 6183   uint max_used_connection= max<uint>(mysql_socket_getfd(ip_sock), mysql_socket_getfd(unix_sock)) + 1;
 
 6186   DBUG_ENTER(
"handle_connections_sockets");
 
 6189   (void) socket_flags;
 
 6192   FD_ZERO(&clientFDs);
 
 6195   if (mysql_socket_getfd(ip_sock) != INVALID_SOCKET)
 
 6197     mysql_socket_set_thread_owner(ip_sock);
 
 6199     fds[socket_count].fd= mysql_socket_getfd(ip_sock);
 
 6200     fds[socket_count].events= POLLIN;
 
 6201     pfs_fds[socket_count]= ip_sock;
 
 6204     FD_SET(mysql_socket_getfd(ip_sock), &clientFDs);
 
 6207     ip_flags = fcntl(mysql_socket_getfd(ip_sock), F_GETFL, 0);
 
 6210 #ifdef HAVE_SYS_UN_H 
 6211   mysql_socket_set_thread_owner(unix_sock);
 
 6213   fds[socket_count].fd= mysql_socket_getfd(unix_sock);
 
 6214   fds[socket_count].events= POLLIN;
 
 6215   pfs_fds[socket_count]= unix_sock;
 
 6218   FD_SET(mysql_socket_getfd(unix_sock), &clientFDs);
 
 6221   socket_flags=fcntl(mysql_socket_getfd(unix_sock), F_GETFL, 0);
 
 6225   DBUG_PRINT(
"general",(
"Waiting for connections."));
 
 6226   MAYBE_BROKEN_SYSCALL;
 
 6230     retval= poll(fds, socket_count, -1);
 
 6234     retval= select((
int) max_used_connection,&readFDs,0,0,0);
 
 6239       if (socket_errno != SOCKET_EINTR)
 
 6246         statistic_increment(connection_errors_select, &LOCK_status);
 
 6247         if (!select_errors++ && !abort_loop)  
 
 6248           sql_print_error(
"mysqld: Got error %d from select",socket_errno); 
 
 6250       MAYBE_BROKEN_SYSCALL
 
 6256       MAYBE_BROKEN_SYSCALL;
 
 6262     for (
int i= 0; i < socket_count; ++
i)
 
 6264       if (fds[i].revents & POLLIN)
 
 6268         flags= fcntl(mysql_socket_getfd(sock), F_GETFL, 0);
 
 6271 #endif // HAVE_FCNTL 
 6276 #ifdef HAVE_SYS_UN_H 
 6277     if (FD_ISSET(mysql_socket_getfd(unix_sock), &readFDs))
 
 6280       flags= socket_flags;
 
 6283 #endif // HAVE_SYS_UN_H 
 6290 #if !defined(NO_FCNTL_NONBLOCK) 
 6291     if (!(test_flags & TEST_BLOCKING))
 
 6293 #if defined(O_NONBLOCK) 
 6294       fcntl(mysql_socket_getfd(sock), F_SETFL, 
flags | O_NONBLOCK);
 
 6295 #elif defined(O_NDELAY) 
 6296       fcntl(mysql_socket_getfd(sock), F_SETFL, 
flags | O_NDELAY);
 
 6300     for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++)
 
 6302       size_socket length= 
sizeof(
struct sockaddr_storage);
 
 6304                                     (
struct sockaddr *)(&cAddr), &length);
 
 6305       if (mysql_socket_getfd(new_sock) != INVALID_SOCKET ||
 
 6306           (socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
 
 6308       MAYBE_BROKEN_SYSCALL;
 
 6309 #if !defined(NO_FCNTL_NONBLOCK) 
 6310       if (!(test_flags & TEST_BLOCKING))
 
 6312         if (retry == MAX_ACCEPT_RETRY - 1)
 
 6313           fcntl(mysql_socket_getfd(sock), F_SETFL, 
flags);    
 
 6317 #if !defined(NO_FCNTL_NONBLOCK) 
 6318     if (!(test_flags & TEST_BLOCKING))
 
 6319       fcntl(mysql_socket_getfd(sock), F_SETFL, 
flags);
 
 6321     if (mysql_socket_getfd(new_sock) == INVALID_SOCKET)
 
 6328       statistic_increment(connection_errors_accept, &LOCK_status);
 
 6329       if ((error_count++ & 255) == 0)   
 
 6330         sql_perror(
"Error in accept");
 
 6331       MAYBE_BROKEN_SYSCALL;
 
 6332       if (socket_errno == SOCKET_ENFILE || socket_errno == SOCKET_EMFILE)
 
 6339       if (mysql_socket_getfd(sock) == mysql_socket_getfd(ip_sock))
 
 6341         struct request_info req;
 
 6342         signal(SIGCHLD, SIG_DFL);
 
 6343         request_init(&req, RQ_DAEMON, libwrapName, RQ_FILE, mysql_socket_getfd(new_sock), NULL);
 
 6346         if (!my_hosts_access(&req))
 
 6353           syslog(deny_severity, 
"refused connect from %s",
 
 6354           my_eval_client(&req));
 
 6363             ((void (*)(int))req.sink)(req.fd);
 
 6371           statistic_increment(connection_errors_tcpwrap, &LOCK_status);
 
 6382     if (!(thd= 
new THD))
 
 6386       statistic_increment(connection_errors_internal, &LOCK_status);
 
 6390     bool is_unix_sock= (mysql_socket_getfd(sock) == mysql_socket_getfd(unix_sock));
 
 6391     enum_vio_type vio_type= (is_unix_sock ? VIO_TYPE_SOCKET : VIO_TYPE_TCPIP);
 
 6392     uint vio_flags= (is_unix_sock ? VIO_LOCALHOST : 0);
 
 6394     vio_tmp= mysql_socket_vio_new(new_sock, vio_type, vio_flags);
 
 6403       if (vio_tmp && thd->net.vio != vio_tmp)
 
 6404         vio_delete(vio_tmp);
 
 6411       statistic_increment(connection_errors_internal, &LOCK_status);
 
 6414     init_net_server_extension(thd);
 
 6415     if (mysql_socket_getfd(sock) == mysql_socket_getfd(unix_sock))
 
 6416       thd->security_ctx->set_host((
char*) my_localhost);
 
 6418     create_new_thread(thd);
 
 6425 pthread_handler_t handle_connections_sockets_thread(
void *arg)
 
 6428   handle_connections_sockets();
 
 6429   decrement_handler_count();
 
 6433 pthread_handler_t handle_connections_namedpipes(
void *arg)
 
 6435   HANDLE hConnectedPipe;
 
 6436   OVERLAPPED connectOverlapped= {0};
 
 6439   DBUG_ENTER(
"handle_connections_namedpipes");
 
 6440   connectOverlapped.hEvent= CreateEvent(NULL, TRUE, FALSE, NULL);
 
 6441   if (!connectOverlapped.hEvent)
 
 6443     sql_print_error(
"Can't create event, last error=%u", GetLastError());
 
 6446   DBUG_PRINT(
"general",(
"Waiting for named pipe connections."));
 
 6450     BOOL fConnected= ConnectNamedPipe(hPipe, &connectOverlapped);
 
 6451     if (!fConnected && (GetLastError() == ERROR_IO_PENDING))
 
 6458         fConnected= GetOverlappedResult(hPipe, &connectOverlapped,&bytes, TRUE);
 
 6463       fConnected = GetLastError() == ERROR_PIPE_CONNECTED;
 
 6467       if ((hPipe= CreateNamedPipe(pipe_name,
 
 6468                                   PIPE_ACCESS_DUPLEX |
 
 6469                                   FILE_FLAG_OVERLAPPED,
 
 6471                                   PIPE_READMODE_BYTE |
 
 6473                                   PIPE_UNLIMITED_INSTANCES,
 
 6474                                   (
int) global_system_variables.
 
 6476                                   (
int) global_system_variables.
 
 6478                                   NMPWAIT_USE_DEFAULT_WAIT,
 
 6479                                   &saPipeSecurity)) ==
 
 6480     INVALID_HANDLE_VALUE)
 
 6482   sql_perror(
"Can't create new named pipe!");
 
 6486     hConnectedPipe = hPipe;
 
 6488     if ((hPipe = CreateNamedPipe(pipe_name,
 
 6489                  PIPE_ACCESS_DUPLEX |
 
 6490                  FILE_FLAG_OVERLAPPED,
 
 6492          PIPE_READMODE_BYTE |
 
 6494          PIPE_UNLIMITED_INSTANCES,
 
 6495          (
int) global_system_variables.net_buffer_length,
 
 6496          (
int) global_system_variables.net_buffer_length,
 
 6497          NMPWAIT_USE_DEFAULT_WAIT,
 
 6498          &saPipeSecurity)) ==
 
 6499   INVALID_HANDLE_VALUE)
 
 6501       sql_perror(
"Can't create new named pipe!");
 
 6502       hPipe=hConnectedPipe;
 
 6506     if (!(thd = 
new THD))
 
 6508       DisconnectNamedPipe(hConnectedPipe);
 
 6509       CloseHandle(hConnectedPipe);
 
 6512     if (!(thd->net.vio= vio_new_win32pipe(hConnectedPipe)) ||
 
 6515       close_connection(thd, ER_OUT_OF_RESOURCES);
 
 6520     thd->security_ctx->set_host(my_strdup(my_localhost, MYF(0)));
 
 6521     create_new_thread(thd);
 
 6523   CloseHandle(connectOverlapped.hEvent);
 
 6525   decrement_handler_count();
 
 6538 pthread_handler_t handle_connections_shared_memory(
void *arg)
 
 6541   HANDLE handle_connect_file_map= 0;
 
 6542   char  *handle_connect_map= 0;                 
 
 6543   HANDLE event_connect_answer= 0;
 
 6544   ulong smem_buffer_length= shared_memory_buffer_length + 4;
 
 6545   ulong connect_number= 1;
 
 6548   char connect_number_char[22], *p;
 
 6549   const char *errmsg= 0;
 
 6550   SECURITY_ATTRIBUTES *sa_event= 0, *sa_mapping= 0;
 
 6552   DBUG_ENTER(
"handle_connections_shared_memorys");
 
 6553   DBUG_PRINT(
"general",(
"Waiting for allocated shared memory."));
 
 6558   if (!(tmp= (
char *)my_malloc(strlen(shared_memory_base_name) + 32L, MYF(MY_FAE))))
 
 6561   if (my_security_attr_create(&sa_event, &errmsg,
 
 6562                               GENERIC_ALL, SYNCHRONIZE | EVENT_MODIFY_STATE))
 
 6565   if (my_security_attr_create(&sa_mapping, &errmsg,
 
 6566                              GENERIC_ALL, FILE_MAP_READ | FILE_MAP_WRITE))
 
 6576   suffix_pos= strxmov(tmp,shared_memory_base_name,
"_",NullS);
 
 6577   strmov(suffix_pos, 
"CONNECT_REQUEST");
 
 6578   if ((smem_event_connect_request= CreateEvent(sa_event,
 
 6579                                                FALSE, FALSE, tmp)) == 0)
 
 6581     errmsg= 
"Could not create request event";
 
 6584   strmov(suffix_pos, 
"CONNECT_ANSWER");
 
 6585   if ((event_connect_answer= CreateEvent(sa_event, FALSE, FALSE, tmp)) == 0)
 
 6587     errmsg=
"Could not create answer event";
 
 6590   strmov(suffix_pos, 
"CONNECT_DATA");
 
 6591   if ((handle_connect_file_map=
 
 6592        CreateFileMapping(INVALID_HANDLE_VALUE, sa_mapping,
 
 6593                          PAGE_READWRITE, 0, 
sizeof(connect_number), tmp)) == 0)
 
 6595     errmsg= 
"Could not create file mapping";
 
 6598   if ((handle_connect_map= (
char *)MapViewOfFile(handle_connect_file_map,
 
 6600               sizeof(DWORD))) == 0)
 
 6602     errmsg= 
"Could not create shared memory service";
 
 6609     WaitForSingleObject(smem_event_connect_request,INFINITE);
 
 6617     HANDLE handle_client_file_map= 0;
 
 6618     char  *handle_client_map= 0;
 
 6619     HANDLE event_client_wrote= 0;
 
 6620     HANDLE event_client_read= 0;    
 
 6621     HANDLE event_server_wrote= 0;
 
 6622     HANDLE event_server_read= 0;
 
 6623     HANDLE event_conn_closed= 0;
 
 6626     p= int10_to_str(connect_number, connect_number_char, 10);
 
 6635     suffix_pos= strxmov(tmp,shared_memory_base_name,
"_",connect_number_char,
 
 6637     strmov(suffix_pos, 
"DATA");
 
 6638     if ((handle_client_file_map=
 
 6639          CreateFileMapping(INVALID_HANDLE_VALUE, sa_mapping,
 
 6640                            PAGE_READWRITE, 0, smem_buffer_length, tmp)) == 0)
 
 6642       errmsg= 
"Could not create file mapping";
 
 6645     if ((handle_client_map= (
char*)MapViewOfFile(handle_client_file_map,
 
 6647               smem_buffer_length)) == 0)
 
 6649       errmsg= 
"Could not create memory map";
 
 6652     strmov(suffix_pos, 
"CLIENT_WROTE");
 
 6653     if ((event_client_wrote= CreateEvent(sa_event, FALSE, FALSE, tmp)) == 0)
 
 6655       errmsg= 
"Could not create client write event";
 
 6658     strmov(suffix_pos, 
"CLIENT_READ");
 
 6659     if ((event_client_read= CreateEvent(sa_event, FALSE, FALSE, tmp)) == 0)
 
 6661       errmsg= 
"Could not create client read event";
 
 6664     strmov(suffix_pos, 
"SERVER_READ");
 
 6665     if ((event_server_read= CreateEvent(sa_event, FALSE, FALSE, tmp)) == 0)
 
 6667       errmsg= 
"Could not create server read event";
 
 6670     strmov(suffix_pos, 
"SERVER_WROTE");
 
 6671     if ((event_server_wrote= CreateEvent(sa_event,
 
 6672                                          FALSE, FALSE, tmp)) == 0)
 
 6674       errmsg= 
"Could not create server write event";
 
 6677     strmov(suffix_pos, 
"CONNECTION_CLOSED");
 
 6678     if ((event_conn_closed= CreateEvent(sa_event,
 
 6679                                         TRUE, FALSE, tmp)) == 0)
 
 6681       errmsg= 
"Could not create closed connection event";
 
 6686     if (!(thd= 
new THD))
 
 6689     int4store(handle_connect_map, connect_number);
 
 6690     if (!SetEvent(event_connect_answer))
 
 6692       errmsg= 
"Could not send answer event";
 
 6696     if (!SetEvent(event_client_read))
 
 6698       errmsg= 
"Could not set client to read mode";
 
 6701     if (!(thd->net.vio= vio_new_win32shared_memory(handle_client_file_map,
 
 6707                                                    event_conn_closed)) ||
 
 6710       close_connection(thd, ER_OUT_OF_RESOURCES);
 
 6714     thd->security_ctx->set_host(my_strdup(my_localhost, MYF(0))); 
 
 6715     create_new_thread(thd);
 
 6724       strxmov(buff, 
"Can't create shared memory connection: ", errmsg, 
".",
 
 6728     if (handle_client_file_map)
 
 6729       CloseHandle(handle_client_file_map);
 
 6730     if (handle_client_map)
 
 6731       UnmapViewOfFile(handle_client_map);
 
 6732     if (event_server_wrote)
 
 6733       CloseHandle(event_server_wrote);
 
 6734     if (event_server_read)
 
 6735       CloseHandle(event_server_read);
 
 6736     if (event_client_wrote)
 
 6737       CloseHandle(event_client_wrote);
 
 6738     if (event_client_read)
 
 6739       CloseHandle(event_client_read);
 
 6740     if (event_conn_closed)
 
 6741       CloseHandle(event_conn_closed);
 
 6753     strxmov(buff, 
"Can't create shared memory service: ", errmsg, 
".", NullS);
 
 6756   my_security_attr_free(sa_event);
 
 6757   my_security_attr_free(sa_mapping);
 
 6758   if (handle_connect_map) UnmapViewOfFile(handle_connect_map);
 
 6759   if (handle_connect_file_map)  CloseHandle(handle_connect_file_map);
 
 6760   if (event_connect_answer) CloseHandle(event_connect_answer);
 
 6761   if (smem_event_connect_request) CloseHandle(smem_event_connect_request);
 
 6763   decrement_handler_count();
 
 6785 int handle_early_options()
 
 6788   vector<my_option> all_early_options;
 
 6789   all_early_options.reserve(100);
 
 6791   my_getopt_register_get_addr(NULL);
 
 6793   my_getopt_skip_unknown= TRUE;
 
 6796   sys_var_add_options(&all_early_options, sys_var::PARSE_EARLY);
 
 6799   for (
my_option *opt= my_long_early_options;
 
 6802     all_early_options.push_back(*opt);
 
 6804   add_terminator(&all_early_options);
 
 6810   buffered_logs.init();
 
 6811   my_getopt_error_reporter= buffered_option_error_reporter;
 
 6812   my_charset_error_reporter= buffered_option_error_reporter;
 
 6814   ho_error= handle_options(&remaining_argc, &remaining_argv,
 
 6815                            &all_early_options[0], mysqld_get_one_option);
 
 6824   vector<my_option>().swap(all_early_options);
 
 6836 void adjust_open_files_limit(ulong *requested_open_files)
 
 6841   ulong request_open_files;
 
 6842   ulong effective_open_files;
 
 6845   limit_1= 10 + max_connections + table_cache_size * 2;
 
 6852   limit_2= max_connections * 5;
 
 6855   limit_3= open_files_limit ? open_files_limit : 5000;
 
 6857   request_open_files= max<ulong>(max<ulong>(limit_1, limit_2), limit_3);
 
 6860   effective_open_files= my_set_max_open_files(request_open_files);
 
 6862   if (effective_open_files < request_open_files)
 
 6866     if (open_files_limit == 0)
 
 6868       snprintf(msg, 
sizeof(msg),
 
 6869                "Changed limits: max_open_files: %lu (requested %lu)",
 
 6870                effective_open_files, request_open_files);
 
 6871       buffered_logs.
buffer(WARNING_LEVEL, msg);
 
 6875       snprintf(msg, 
sizeof(msg),
 
 6876                "Could not increase number of max_open_files to " 
 6877                "more than %lu (request: %lu)",
 
 6878                effective_open_files, request_open_files);
 
 6879       buffered_logs.
buffer(WARNING_LEVEL, msg);
 
 6883   open_files_limit= effective_open_files;
 
 6884   if (requested_open_files)
 
 6885     *requested_open_files= min<ulong>(effective_open_files, request_open_files);
 
 6888 void adjust_max_connections(ulong requested_open_files)
 
 6892   limit= requested_open_files - 10 - TABLE_OPEN_CACHE_MIN * 2;
 
 6894   if (limit < max_connections)
 
 6898     snprintf(msg, 
sizeof(msg),
 
 6899              "Changed limits: max_connections: %lu (requested %lu)",
 
 6900              limit, max_connections);
 
 6901     buffered_logs.
buffer(WARNING_LEVEL, msg);
 
 6903     max_connections= 
limit;
 
 6907 void adjust_table_cache_size(ulong requested_open_files)
 
 6911   limit= max<ulong>((requested_open_files - 10 - max_connections) / 2,
 
 6912                     TABLE_OPEN_CACHE_MIN);
 
 6914   if (limit < table_cache_size)
 
 6918     snprintf(msg, 
sizeof(msg),
 
 6919              "Changed limits: table_cache: %lu (requested %lu)",
 
 6920              limit, table_cache_size);
 
 6921     buffered_logs.
buffer(WARNING_LEVEL, msg);
 
 6923     table_cache_size= 
limit;
 
 6926   table_cache_size_per_instance= table_cache_size / table_cache_instances;
 
 6929 void adjust_table_def_size()
 
 6931   longlong default_value;
 
 6934   default_value= min<longlong> (400 + table_cache_size / 2, 2000);
 
 6935   var= intern_find_sys_var(STRING_WITH_LEN(
"table_definition_cache"));
 
 6936   DBUG_ASSERT(var != NULL);
 
 6937   var->update_default(default_value);
 
 6939   if (! table_definition_cache_specified)
 
 6940     table_def_size= default_value;
 
 6943 void adjust_related_options(ulong *requested_open_files)
 
 6950   adjust_open_files_limit(requested_open_files);
 
 6951   adjust_max_connections(*requested_open_files);
 
 6952   adjust_table_cache_size(*requested_open_files);
 
 6953   adjust_table_def_size();
 
 6956 vector<my_option> all_options;
 
 6958 struct my_option my_long_early_options[]=
 
 6960 #ifndef DISABLE_GRANT_OPTIONS 
 6961   {
"bootstrap", OPT_BOOTSTRAP, 
"Used by mysql installation scripts.", 0, 0, 0,
 
 6962    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 6964 #ifndef DISABLE_GRANT_OPTIONS 
 6965   {
"skip-grant-tables", 0,
 
 6966    "Start without grant tables. This gives all users FULL ACCESS to all tables.",
 
 6967    &opt_noacl, &opt_noacl, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
 
 6970   {
"help", 
'?', 
"Display this help and exit.",
 
 6971    &opt_help, &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
 6973   {
"verbose", 
'v', 
"Used with --help option for detailed help.",
 
 6974    &opt_verbose, &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 6975   {
"version", 
'V', 
"Output version information and exit.", 0, 0, 0, GET_NO_ARG,
 
 6976    NO_ARG, 0, 0, 0, 0, 0, 0},
 
 6977   {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
 6988 #ifdef HAVE_REPLICATION 
 6989   {
"abort-slave-event-count", 0,
 
 6990    "Option used by mysql-test for debugging and testing of replication.",
 
 6991    &abort_slave_event_count,  &abort_slave_event_count,
 
 6992    0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 6994   {
"allow-suspicious-udfs", 0,
 
 6995    "Allows use of UDFs consisting of only one symbol xxx() " 
 6996    "without corresponding xxx_init() or xxx_deinit(). That also means " 
 6997    "that one can load any function from any library, for example exit() " 
 6999    &opt_allow_suspicious_udfs, &opt_allow_suspicious_udfs,
 
 7000    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7001   {
"ansi", 
'a', 
"Use ANSI SQL syntax instead of MySQL syntax. This mode " 
 7002    "will also set transaction isolation level 'serializable'.", 0, 0, 0,
 
 7003    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7008   {
"autocommit", 0, 
"Set default value for autocommit (0 or 1)",
 
 7009    &opt_autocommit, &opt_autocommit, 0,
 
 7010    GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, NULL},
 
 7011   {
"binlog-do-db", OPT_BINLOG_DO_DB,
 
 7012    "Tells the master it should log updates for the specified database, " 
 7013    "and exclude all others not explicitly mentioned.",
 
 7014    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7015   {
"binlog-ignore-db", OPT_BINLOG_IGNORE_DB,
 
 7016    "Tells the master that updates to the given database should not be logged to the binary log.",
 
 7017    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7018   {
"binlog-row-event-max-size", 0,
 
 7019    "The maximum size of a row-based binary log event in bytes. Rows will be " 
 7020    "grouped into events smaller than this size if possible. " 
 7021    "The value has to be a multiple of 256.",
 
 7022    &opt_binlog_rows_event_max_size, &opt_binlog_rows_event_max_size,
 
 7023    0, GET_ULONG, REQUIRED_ARG,
 
 7024     8192,   256,  ULONG_MAX,
 
 7028   {
"character-set-client-handshake", 0,
 
 7029    "Don't ignore client side character set value sent during handshake.",
 
 7030    &opt_character_set_client_handshake,
 
 7031    &opt_character_set_client_handshake,
 
 7032     0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
 7033   {
"character-set-filesystem", 0,
 
 7034    "Set the filesystem character set.",
 
 7035    &character_set_filesystem_name,
 
 7036    &character_set_filesystem_name,
 
 7037    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
 7038   {
"character-set-server", 
'C', 
"Set the default character set.",
 
 7039    &default_character_set_name, &default_character_set_name,
 
 7040    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
 7041   {
"chroot", 
'r', 
"Chroot mysqld daemon during startup.",
 
 7042    &mysqld_chroot, &mysqld_chroot, 0, GET_STR, REQUIRED_ARG,
 
 7044   {
"collation-server", 0, 
"Set the default collation.",
 
 7045    &default_collation_name, &default_collation_name,
 
 7046    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
 7047   {
"console", OPT_CONSOLE, 
"Write error output on screen; don't remove the console window on windows.",
 
 7048    &opt_console, &opt_console, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
 7050   {
"core-file", OPT_WANT_CORE, 
"Write core on errors.", 0, 0, 0, GET_NO_ARG,
 
 7051    NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7055   {
"default-storage-engine", 0, 
"The default storage engine for new tables",
 
 7056    &default_storage_engine, 0, 0, GET_STR, REQUIRED_ARG,
 
 7058   {
"default-tmp-storage-engine", 0, 
 
 7059     "The default storage engine for new explict temporary tables",
 
 7060    &default_tmp_storage_engine, 0, 0, GET_STR, REQUIRED_ARG,
 
 7062   {
"default-time-zone", 0, 
"Set the default time zone.",
 
 7063    &default_tz_name, &default_tz_name,
 
 7064    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
 7067    "Load keys for des_encrypt() and des_encrypt from given file.",
 
 7068    &des_key_file, &des_key_file, 0, GET_STR, REQUIRED_ARG,
 
 7071 #ifdef HAVE_REPLICATION 
 7072   {
"disconnect-slave-event-count", 0,
 
 7073    "Option used by mysql-test for debugging and testing of replication.",
 
 7074    &disconnect_slave_event_count, &disconnect_slave_event_count,
 
 7075    0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7077   {
"exit-info", 
'T', 
"Used for debugging. Use at your own risk.", 0, 0, 0,
 
 7078    GET_LONG, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
 7080   {
"external-locking", 0, 
"Use system (external) locking (disabled by " 
 7081    "default).  With this option enabled you can run myisamchk to test " 
 7082    "(not repair) tables while the MySQL server is running. Disable with " 
 7083    "--skip-external-locking.", &opt_external_locking, &opt_external_locking,
 
 7084    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7088    "Set up signals usable for debugging.",
 
 7089    &opt_debugging, &opt_debugging,
 
 7090    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7091 #ifdef HAVE_LARGE_PAGE_OPTION 
 7092   {
"super-large-pages", 0, 
"Enable support for super large pages.",
 
 7093    &opt_super_large_pages, &opt_super_large_pages, 0,
 
 7094    GET_BOOL, OPT_ARG, 0, 0, 1, 0, 1, 0},
 
 7096   {
"ignore-db-dir", OPT_IGNORE_DB_DIRECTORY,
 
 7097    "Specifies a directory to add to the ignore list when collecting " 
 7098    "database names from the datadir. Put a blank argument to reset " 
 7099    "the list accumulated so far.", 0, 0, 0, GET_STR, REQUIRED_ARG, 
 
 7102    "Client error messages in given language. May be given as a full path. " 
 7103    "Deprecated. Use --lc-messages-dir instead.",
 
 7104    &lc_messages_dir_ptr, &lc_messages_dir_ptr, 0,
 
 7105    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7107    "Set the language used for the error messages.",
 
 7108    &lc_messages, &lc_messages, 0, GET_STR, REQUIRED_ARG,
 
 7110   {
"lc-time-names", 0,
 
 7111    "Set the language used for the month names and the days of the week.",
 
 7112    &lc_time_names_name, &lc_time_names_name,
 
 7113    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
 7114   {
"log-bin", OPT_BIN_LOG,
 
 7115    "Log update queries in binary format. Optional (but strongly recommended " 
 7116    "to avoid replication problems if server's hostname changes) argument " 
 7117    "should be the chosen location for the binary log files.",
 
 7118    &opt_bin_logname, &opt_bin_logname, 0, GET_STR_ALLOC,
 
 7119    OPT_ARG, 0, 0, 0, 0, 0, 0},
 
 7120   {
"log-bin-index", 0,
 
 7121    "File that holds the names for binary log files.",
 
 7122    &opt_binlog_index_name, &opt_binlog_index_name, 0, GET_STR,
 
 7123    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7124   {
"relay-log-index", 0,
 
 7125    "File that holds the names for relay log files.",
 
 7126    &opt_relaylog_index_name, &opt_relaylog_index_name, 0, GET_STR,
 
 7127    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7128   {
"log-isam", OPT_ISAM_LOG, 
"Log all MyISAM changes to file.",
 
 7129    &myisam_log_filename, &myisam_log_filename, 0, GET_STR,
 
 7130    OPT_ARG, 0, 0, 0, 0, 0, 0},
 
 7132    "Log to general log before any rewriting of the query. For use in debugging, not production as " 
 7133    "sensitive information may be logged.",
 
 7134    &opt_log_raw, &opt_log_raw,
 
 7135    0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0 },
 
 7136   {
"log-short-format", 0,
 
 7137    "Don't log extra information to update and slow-query logs.",
 
 7138    &opt_short_log_format, &opt_short_log_format,
 
 7139    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7141    "Path to transaction coordinator log (used for transactions that affect " 
 7142    "more than one storage engine, when binary log is disabled).",
 
 7143    &opt_tc_log_file, &opt_tc_log_file, 0, GET_STR,
 
 7144    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7146   {
"log-tc-size", 0, 
"Size of transaction coordinator log.",
 
 7147    &opt_tc_log_size, &opt_tc_log_size, 0, GET_ULONG,
 
 7148    REQUIRED_ARG, TC_LOG_MIN_SIZE, TC_LOG_MIN_SIZE, ULONG_MAX, 0,
 
 7149    TC_LOG_PAGE_SIZE, 0},
 
 7151   {
"master-info-file", 0,
 
 7152    "The location and name of the file that remembers the master and where " 
 7153    "the I/O replication thread is in the master's binlogs.",
 
 7154    &master_info_file, &master_info_file, 0, GET_STR,
 
 7155    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7156   {
"master-retry-count", OPT_MASTER_RETRY_COUNT,
 
 7157    "The number of tries the slave will make to connect to the master before giving up. " 
 7158    "Deprecated option, use 'CHANGE MASTER TO master_retry_count = <num>' instead.",
 
 7159    &master_retry_count, &master_retry_count, 0, GET_ULONG,
 
 7160    REQUIRED_ARG, 3600*24, 0, 0, 0, 0, 0},
 
 7161 #ifdef HAVE_REPLICATION 
 7162   {
"max-binlog-dump-events", 0,
 
 7163    "Option used by mysql-test for debugging and testing of replication.",
 
 7164    &max_binlog_dump_events, &max_binlog_dump_events, 0,
 
 7165    GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7167   {
"memlock", 0, 
"Lock mysqld in memory.", &locked_in_memory,
 
 7168    &locked_in_memory, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7169   {
"old-style-user-limits", 0,
 
 7170    "Enable old-style user limits (before 5.0.3, user resources were counted " 
 7171    "per each user+host vs. per account).",
 
 7172    &opt_old_style_user_limits, &opt_old_style_user_limits,
 
 7173    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7174   {
"port-open-timeout", 0,
 
 7175    "Maximum time in seconds to wait for the port to become free. " 
 7176    "(Default: No wait).", &mysqld_port_timeout, &mysqld_port_timeout, 0,
 
 7177    GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7178   {
"replicate-do-db", OPT_REPLICATE_DO_DB,
 
 7179    "Tells the slave thread to restrict replication to the specified database. " 
 7180    "To specify more than one database, use the directive multiple times, " 
 7181    "once for each database. Note that this will only work if you do not use " 
 7182    "cross-database queries such as UPDATE some_db.some_table SET foo='bar' " 
 7183    "while having selected a different or no database. If you need cross " 
 7184    "database updates to work, make sure you have 3.23.28 or later, and use " 
 7185    "replicate-wild-do-table=db_name.%.",
 
 7186    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7187   {
"replicate-do-table", OPT_REPLICATE_DO_TABLE,
 
 7188    "Tells the slave thread to restrict replication to the specified table. " 
 7189    "To specify more than one table, use the directive multiple times, once " 
 7190    "for each table. This will work for cross-database updates, in contrast " 
 7191    "to replicate-do-db.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7192   {
"replicate-ignore-db", OPT_REPLICATE_IGNORE_DB,
 
 7193    "Tells the slave thread to not replicate to the specified database. To " 
 7194    "specify more than one database to ignore, use the directive multiple " 
 7195    "times, once for each database. This option will not work if you use " 
 7196    "cross database updates. If you need cross database updates to work, " 
 7197    "make sure you have 3.23.28 or later, and use replicate-wild-ignore-" 
 7198    "table=db_name.%. ", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7199   {
"replicate-ignore-table", OPT_REPLICATE_IGNORE_TABLE,
 
 7200    "Tells the slave thread to not replicate to the specified table. To specify " 
 7201    "more than one table to ignore, use the directive multiple times, once for " 
 7202    "each table. This will work for cross-database updates, in contrast to " 
 7203    "replicate-ignore-db.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7204   {
"replicate-rewrite-db", OPT_REPLICATE_REWRITE_DB,
 
 7205    "Updates to a database with a different name than the original. Example: " 
 7206    "replicate-rewrite-db=master_db_name->slave_db_name.",
 
 7207    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7208 #ifdef HAVE_REPLICATION 
 7209   {
"replicate-same-server-id", 0,
 
 7210    "In replication, if set to 1, do not skip events having our server id. " 
 7211    "Default value is 0 (to break infinite loops in circular replication). " 
 7212    "Can't be set to 1 if --log-slave-updates is used.",
 
 7213    &replicate_same_server_id, &replicate_same_server_id,
 
 7214    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7216   {
"replicate-wild-do-table", OPT_REPLICATE_WILD_DO_TABLE,
 
 7217    "Tells the slave thread to restrict replication to the tables that match " 
 7218    "the specified wildcard pattern. To specify more than one table, use the " 
 7219    "directive multiple times, once for each table. This will work for cross-" 
 7220    "database updates. Example: replicate-wild-do-table=foo%.bar% will " 
 7221    "replicate only updates to tables in all databases that start with foo " 
 7222    "and whose table names start with bar.",
 
 7223    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7224   {
"replicate-wild-ignore-table", OPT_REPLICATE_WILD_IGNORE_TABLE,
 
 7225    "Tells the slave thread to not replicate to the tables that match the " 
 7226    "given wildcard pattern. To specify more than one table to ignore, use " 
 7227    "the directive multiple times, once for each table. This will work for " 
 7228    "cross-database updates. Example: replicate-wild-ignore-table=foo%.bar% " 
 7229    "will not do updates to tables in databases that start with foo and whose " 
 7230    "table names start with bar.",
 
 7231    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7232   {
"safe-user-create", 0,
 
 7233    "Don't allow new user creation by the user who has no write privileges to the mysql.user table.",
 
 7234    &opt_safe_user_create, &opt_safe_user_create, 0, GET_BOOL,
 
 7235    NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7236   {
"show-slave-auth-info", 0,
 
 7237    "Show user and password in SHOW SLAVE HOSTS on this master.",
 
 7238    &opt_show_slave_auth_info, &opt_show_slave_auth_info, 0,
 
 7239    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7240   {
"skip-host-cache", OPT_SKIP_HOST_CACHE, 
"Don't cache host names.", 0, 0, 0,
 
 7241    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7242   {
"skip-new", OPT_SKIP_NEW, 
"Don't use new, possibly wrong routines.",
 
 7243    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7244   {
"skip-slave-start", 0,
 
 7245    "If set, slave is not autostarted.", &opt_skip_slave_start,
 
 7246    &opt_skip_slave_start, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7247   {
"skip-stack-trace", OPT_SKIP_STACK_TRACE,
 
 7248    "Don't print a stack trace on failure.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
 
 7250 #if defined(_WIN32) && !defined(EMBEDDED_LIBRARY) 
 7251   {
"slow-start-timeout", 0,
 
 7252    "Maximum number of milliseconds that the service control manager should wait " 
 7253    "before trying to kill the windows service during startup" 
 7254    "(Default: 15000).", &slow_start_timeout, &slow_start_timeout, 0,
 
 7255    GET_ULONG, REQUIRED_ARG, 15000, 0, 0, 0, 0, 0},
 
 7257 #ifdef HAVE_REPLICATION 
 7258   {
"sporadic-binlog-dump-fail", 0,
 
 7259    "Option used by mysql-test for debugging and testing of replication.",
 
 7260    &opt_sporadic_binlog_dump_fail,
 
 7261    &opt_sporadic_binlog_dump_fail, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
 
 7266    "Enable SSL for connection (automatically enabled with other flags).",
 
 7267    &opt_use_ssl, &opt_use_ssl, 0, GET_BOOL, OPT_ARG, 0, 0, 0,
 
 7272   "Dummy option to start as a standalone program (NT).", 0, 0, 0, GET_NO_ARG,
 
 7273    NO_ARG, 0, 0, 0, 0, 0, 0},
 
 7275   {
"symbolic-links", 
's', 
"Enable symbolic link support.",
 
 7276    &my_use_symdir, &my_use_symdir, 0, GET_BOOL, NO_ARG,
 
 7282    IF_PURIFY(0,1), 0, 0, 0, 0, 0},
 
 7283   {
"sysdate-is-now", 0,
 
 7284    "Non-default option to alias SYSDATE() to NOW() to make it safe-replicable. " 
 7285    "Since 5.0, SYSDATE() returns a `dynamic' value different for different " 
 7286    "invocations, even within the same statement.",
 
 7287    &global_system_variables.sysdate_is_now,
 
 7288    0, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
 
 7289   {
"tc-heuristic-recover", 0,
 
 7290    "Decision to use in heuristic recover process. Possible values are COMMIT " 
 7291    "or ROLLBACK.", &tc_heuristic_recover, &tc_heuristic_recover,
 
 7292    &tc_heuristic_recover_typelib, GET_ENUM, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7293 #if defined(ENABLED_DEBUG_SYNC) 
 7294   {
"debug-sync-timeout", OPT_DEBUG_SYNC_TIMEOUT,
 
 7295    "Enable the debug sync facility " 
 7296    "and optionally specify a default wait timeout in seconds. " 
 7297    "A zero value keeps the facility disabled.",
 
 7298    &opt_debug_sync_timeout, 0,
 
 7299    0, GET_UINT, OPT_ARG, 0, 0, UINT_MAX, 0, 0, 0},
 
 7302 #if (ENABLE_TEMP_POOL) 
 7303    "Using this option will cause most temporary files created to use a small " 
 7304    "set of names, rather than a unique name for each new file.",
 
 7306    "This option is ignored on this OS.",
 
 7308    &use_temp_pool, &use_temp_pool, 0, GET_BOOL, NO_ARG, 1,
 
 7310   {
"transaction-isolation", 0,
 
 7311    "Default transaction isolation level.",
 
 7312    &global_system_variables.tx_isolation,
 
 7313    &global_system_variables.tx_isolation, &tx_isolation_typelib,
 
 7314    GET_ENUM, REQUIRED_ARG, ISO_REPEATABLE_READ, 0, 0, 0, 0, 0},
 
 7315   {
"transaction-read-only", 0,
 
 7316    "Default transaction access mode. " 
 7317    "True if transactions are read-only.",
 
 7320    GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
 7321   {
"user", 
'u', 
"Run mysqld daemon as user.", 0, 0, 0, GET_STR, REQUIRED_ARG,
 
 7323   {
"plugin-load", OPT_PLUGIN_LOAD,
 
 7324    "Optional semicolon-separated list of plugins to load, where each plugin is " 
 7325    "identified as name=library, where name is the plugin name and library " 
 7326    "is the plugin library in plugin_dir.",
 
 7328    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7329   {
"plugin-load-add", OPT_PLUGIN_LOAD_ADD,
 
 7330    "Optional semicolon-separated list of plugins to load, where each plugin is " 
 7331    "identified as name=library, where name is the plugin name and library " 
 7332    "is the plugin library in plugin_dir. This option adds to the list " 
 7333    "speficied by --plugin-load in an incremental way. " 
 7334    "Multiple --plugin-load-add are supported.",
 
 7336    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7337   {
"default_authentication_plugin", OPT_DEFAULT_AUTH,
 
 7338    "Defines what password- and authentication algorithm to use per default",
 
 7340    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
 7341   {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
 7345 static int show_queries(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7347   var->type= SHOW_LONGLONG;
 
 7348   var->value= (
char *)&thd->query_id;
 
 7353 static int show_net_compression(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7355   var->type= SHOW_MY_BOOL;
 
 7356   var->value= (
char *)&thd->net.compress;
 
 7360 static int show_starttime(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7362   var->type= SHOW_LONGLONG;
 
 7364   *((longlong *)buff)= (longlong) (thd->query_start() - server_start_time);
 
 7368 #ifdef ENABLED_PROFILING 
 7369 static int show_flushstatustime(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7371   var->type= SHOW_LONGLONG;
 
 7373   *((longlong *)buff)= (longlong) (thd->query_start() - flush_status_time);
 
 7378 #ifdef HAVE_REPLICATION 
 7379 static int show_slave_running(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7381   var->type= SHOW_MY_BOOL;
 
 7383   *((my_bool *)buff)= (my_bool) (active_mi &&
 
 7384                                  active_mi->slave_running == MYSQL_SLAVE_RUN_CONNECT &&
 
 7385                                  active_mi->rli->slave_running);
 
 7389 static int show_slave_retried_trans(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7397     var->type= SHOW_LONG;
 
 7399     *((
long *)buff)= (long)active_mi->rli->retried_trans;
 
 7402     var->type= SHOW_UNDEF;
 
 7406 static int show_slave_received_heartbeats(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7410     var->type= SHOW_LONGLONG;
 
 7412     *((longlong *)buff)= active_mi->received_heartbeats;
 
 7415     var->type= SHOW_UNDEF;
 
 7419 static int show_slave_last_heartbeat(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7424     var->type= SHOW_CHAR;
 
 7426     if (active_mi->last_heartbeat == 0)
 
 7430       thd->variables.time_zone->gmt_sec_to_TIME(&received_heartbeat_time, 
 
 7431         active_mi->last_heartbeat);
 
 7432       my_datetime_to_str(&received_heartbeat_time, buff, 0);
 
 7436     var->type= SHOW_UNDEF;
 
 7440 static int show_heartbeat_period(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7442   DEBUG_SYNC(thd, 
"dsync_show_heartbeat_period");
 
 7445     var->type= SHOW_CHAR;
 
 7447     sprintf(buff, 
"%.3f", active_mi->heartbeat_period);
 
 7450     var->type= SHOW_UNDEF;
 
 7455 static int show_slave_rows_last_search_algorithm_used(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7457   uint res= slave_rows_last_search_algorithm_used;
 
 7458   const char* s= ((res == Rows_log_event::ROW_LOOKUP_TABLE_SCAN) ? 
"TABLE_SCAN" :
 
 7459                   ((res == Rows_log_event::ROW_LOOKUP_HASH_SCAN) ? 
"HASH_SCAN" : 
 
 7462   var->type= SHOW_CHAR;
 
 7464   sprintf(buff, 
"%s", s);
 
 7472 static int show_open_tables(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7474   var->type= SHOW_LONG;
 
 7480 static int show_prepared_stmt_count(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7482   var->type= SHOW_LONG;
 
 7485   *((
long *)buff)= (long)prepared_stmt_count;
 
 7490 static int show_table_definitions(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7492   var->type= SHOW_LONG;
 
 7494   *((
long *)buff)= (long)cached_table_definitions();
 
 7498 #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) 
 7500 static int show_ssl_ctx_sess_accept(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7502   var->type= SHOW_LONG;
 
 7504   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7505                      SSL_CTX_sess_accept(ssl_acceptor_fd->ssl_context));
 
 7509 static int show_ssl_ctx_sess_accept_good(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7511   var->type= SHOW_LONG;
 
 7513   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7514                      SSL_CTX_sess_accept_good(ssl_acceptor_fd->ssl_context));
 
 7518 static int show_ssl_ctx_sess_connect_good(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7520   var->type= SHOW_LONG;
 
 7522   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7523                      SSL_CTX_sess_connect_good(ssl_acceptor_fd->ssl_context));
 
 7527 static int show_ssl_ctx_sess_accept_renegotiate(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7529   var->type= SHOW_LONG;
 
 7531   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7532                      SSL_CTX_sess_accept_renegotiate(ssl_acceptor_fd->ssl_context));
 
 7536 static int show_ssl_ctx_sess_connect_renegotiate(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7538   var->type= SHOW_LONG;
 
 7540   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7541                      SSL_CTX_sess_connect_renegotiate(ssl_acceptor_fd->ssl_context));
 
 7545 static int show_ssl_ctx_sess_cb_hits(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7547   var->type= SHOW_LONG;
 
 7549   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7550                      SSL_CTX_sess_cb_hits(ssl_acceptor_fd->ssl_context));
 
 7554 static int show_ssl_ctx_sess_hits(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7556   var->type= SHOW_LONG;
 
 7558   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7559                      SSL_CTX_sess_hits(ssl_acceptor_fd->ssl_context));
 
 7563 static int show_ssl_ctx_sess_cache_full(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7565   var->type= SHOW_LONG;
 
 7567   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7568                      SSL_CTX_sess_cache_full(ssl_acceptor_fd->ssl_context));
 
 7572 static int show_ssl_ctx_sess_misses(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7574   var->type= SHOW_LONG;
 
 7576   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7577                      SSL_CTX_sess_misses(ssl_acceptor_fd->ssl_context));
 
 7581 static int show_ssl_ctx_sess_timeouts(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7583   var->type= SHOW_LONG;
 
 7585   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7586                      SSL_CTX_sess_timeouts(ssl_acceptor_fd->ssl_context));
 
 7590 static int show_ssl_ctx_sess_number(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7592   var->type= SHOW_LONG;
 
 7594   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7595                      SSL_CTX_sess_number(ssl_acceptor_fd->ssl_context));
 
 7599 static int show_ssl_ctx_sess_connect(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7601   var->type= SHOW_LONG;
 
 7603   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7604                      SSL_CTX_sess_connect(ssl_acceptor_fd->ssl_context));
 
 7608 static int show_ssl_ctx_sess_get_cache_size(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7610   var->type= SHOW_LONG;
 
 7612   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7613                      SSL_CTX_sess_get_cache_size(ssl_acceptor_fd->ssl_context));
 
 7617 static int show_ssl_ctx_get_verify_mode(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7619   var->type= SHOW_LONG;
 
 7621   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7622                      SSL_CTX_get_verify_mode(ssl_acceptor_fd->ssl_context));
 
 7626 static int show_ssl_ctx_get_verify_depth(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7628   var->type= SHOW_LONG;
 
 7630   *((
long *)buff)= (!ssl_acceptor_fd ? 0 :
 
 7631                      SSL_CTX_get_verify_depth(ssl_acceptor_fd->ssl_context));
 
 7635 static int show_ssl_ctx_get_session_cache_mode(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7637   var->type= SHOW_CHAR;
 
 7638   if (!ssl_acceptor_fd)
 
 7639     var->value= 
const_cast<char*
>(
"NONE");
 
 7641     switch (SSL_CTX_get_session_cache_mode(ssl_acceptor_fd->ssl_context))
 
 7643     case SSL_SESS_CACHE_OFF:
 
 7644       var->value= 
const_cast<char*
>(
"OFF"); 
break;
 
 7645     case SSL_SESS_CACHE_CLIENT:
 
 7646       var->value= 
const_cast<char*
>(
"CLIENT"); 
break;
 
 7647     case SSL_SESS_CACHE_SERVER:
 
 7648       var->value= 
const_cast<char*
>(
"SERVER"); 
break;
 
 7649     case SSL_SESS_CACHE_BOTH:
 
 7650       var->value= 
const_cast<char*
>(
"BOTH"); 
break;
 
 7651     case SSL_SESS_CACHE_NO_AUTO_CLEAR:
 
 7652       var->value= 
const_cast<char*
>(
"NO_AUTO_CLEAR"); 
break;
 
 7653     case SSL_SESS_CACHE_NO_INTERNAL_LOOKUP:
 
 7654       var->value= 
const_cast<char*
>(
"NO_INTERNAL_LOOKUP"); 
break;
 
 7656       var->value= 
const_cast<char*
>(
"Unknown"); 
break;
 
 7668 static int show_ssl_get_version(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7670   var->type= SHOW_CHAR;
 
 7671   if( thd->vio_ok() && thd->net.vio->ssl_arg )
 
 7672     var->value= const_cast<char*>(SSL_get_version((SSL*) thd->net.vio->ssl_arg));
 
 7674     var->value= (
char *)
"";
 
 7678 static int show_ssl_session_reused(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7680   var->type= SHOW_LONG;
 
 7682   if( thd->vio_ok() && thd->net.vio->ssl_arg )
 
 7683     *((
long *)buff)= (
long)SSL_session_reused((SSL*) thd->net.vio->ssl_arg);
 
 7689 static int show_ssl_get_default_timeout(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7691   var->type= SHOW_LONG;
 
 7693   if( thd->vio_ok() && thd->net.vio->ssl_arg )
 
 7694     *((
long *)buff)= (
long)SSL_get_default_timeout((SSL*)thd->net.vio->ssl_arg);
 
 7700 static int show_ssl_get_verify_mode(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7702   var->type= SHOW_LONG;
 
 7704   if( thd->net.vio && thd->net.vio->ssl_arg )
 
 7705     *((
long *)buff)= (long)SSL_get_verify_mode((SSL*)thd->net.vio->ssl_arg);
 
 7711 static int show_ssl_get_verify_depth(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7713   var->type= SHOW_LONG;
 
 7715   if( thd->vio_ok() && thd->net.vio->ssl_arg )
 
 7716     *((
long *)buff)= (
long)SSL_get_verify_depth((SSL*)thd->net.vio->ssl_arg);
 
 7722 static int show_ssl_get_cipher(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7724   var->type= SHOW_CHAR;
 
 7725   if( thd->vio_ok() && thd->net.vio->ssl_arg )
 
 7726     var->value= const_cast<char*>(SSL_get_cipher((SSL*) thd->net.vio->ssl_arg));
 
 7728     var->value= (
char *)
"";
 
 7732 static int show_ssl_get_cipher_list(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7734   var->type= SHOW_CHAR;
 
 7736   if (thd->vio_ok() && thd->net.vio->ssl_arg)
 
 7740     char *end= buff + SHOW_VAR_FUNC_BUFF_SIZE;
 
 7741     for (i=0; (p= SSL_get_cipher_list((SSL*) thd->net.vio->ssl_arg,i)) &&
 
 7744       buff= strnmov(buff, p, end-buff-1);
 
 7758 my_asn1_time_to_string(ASN1_TIME *time, 
char *buf, 
size_t len)
 
 7760   return yaSSL_ASN1_TIME_to_string(time, buf, len);
 
 7766 my_asn1_time_to_string(ASN1_TIME *time, 
char *buf, 
size_t len)
 
 7770   BIO *bio= BIO_new(BIO_s_mem());
 
 7775   if (!ASN1_TIME_print(bio, time))
 
 7778   n_read= BIO_read(bio, buf, (
int) (len - 1));
 
 7806 show_ssl_get_server_not_before(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7808   var->type= SHOW_CHAR;
 
 7809   if(thd->vio_ok() && thd->net.vio->ssl_arg)
 
 7811     SSL *ssl= (SSL*) thd->net.vio->ssl_arg;
 
 7812     X509 *cert= SSL_get_certificate(ssl);
 
 7813     ASN1_TIME *not_before= X509_get_notBefore(cert);
 
 7815     var->value= my_asn1_time_to_string(not_before, buff,
 
 7816                                        SHOW_VAR_FUNC_BUFF_SIZE);
 
 7822     var->value= empty_c_string;
 
 7839 show_ssl_get_server_not_after(THD *thd, 
SHOW_VAR *var, 
char *buff)
 
 7841   var->type= SHOW_CHAR;
 
 7842   if(thd->vio_ok() && thd->net.vio->ssl_arg)
 
 7844     SSL *ssl= (SSL*) thd->net.vio->ssl_arg;
 
 7845     X509 *cert= SSL_get_certificate(ssl);
 
 7846     ASN1_TIME *not_after= X509_get_notAfter(cert);
 
 7848     var->value= my_asn1_time_to_string(not_after, buff,
 
 7849                                        SHOW_VAR_FUNC_BUFF_SIZE);
 
 7854     var->value= empty_c_string;
 
 7866   {
"Aborted_clients",          (
char*) &aborted_threads,        SHOW_LONG},
 
 7867   {
"Aborted_connects",         (
char*) &aborted_connects,       SHOW_LONG},
 
 7868   {
"Binlog_cache_disk_use",    (
char*) &binlog_cache_disk_use,  SHOW_LONG},
 
 7869   {
"Binlog_cache_use",         (
char*) &binlog_cache_use,       SHOW_LONG},
 
 7870   {
"Binlog_stmt_cache_disk_use",(
char*) &binlog_stmt_cache_disk_use,  SHOW_LONG},
 
 7871   {
"Binlog_stmt_cache_use",    (
char*) &binlog_stmt_cache_use,       SHOW_LONG},
 
 7872   {
"Bytes_received",           (
char*) offsetof(
STATUS_VAR, bytes_received), SHOW_LONGLONG_STATUS},
 
 7873   {
"Bytes_sent",               (
char*) offsetof(
STATUS_VAR, bytes_sent), SHOW_LONGLONG_STATUS},
 
 7874   {
"Com",                      (
char*) com_status_vars, SHOW_ARRAY},
 
 7875   {
"Compression",              (
char*) &show_net_compression, SHOW_FUNC},
 
 7876   {
"Connections",              (
char*) &thread_id,              SHOW_LONG_NOFLUSH},
 
 7877   {
"Connection_errors_accept", (
char*) &connection_errors_accept, SHOW_LONG},
 
 7878   {
"Connection_errors_internal", (
char*) &connection_errors_internal, SHOW_LONG},
 
 7879   {
"Connection_errors_max_connections", (
char*) &connection_errors_max_connection, SHOW_LONG},
 
 7880   {
"Connection_errors_peer_address", (
char*) &connection_errors_peer_addr, SHOW_LONG},
 
 7881   {
"Connection_errors_select", (
char*) &connection_errors_select, SHOW_LONG},
 
 7882   {
"Connection_errors_tcpwrap", (
char*) &connection_errors_tcpwrap, SHOW_LONG},
 
 7883   {
"Created_tmp_disk_tables",  (
char*) offsetof(
STATUS_VAR, created_tmp_disk_tables), SHOW_LONGLONG_STATUS},
 
 7884   {
"Created_tmp_files",        (
char*) &my_tmp_file_created, SHOW_LONG},
 
 7885   {
"Created_tmp_tables",       (
char*) offsetof(
STATUS_VAR, created_tmp_tables), SHOW_LONGLONG_STATUS},
 
 7886   {
"Delayed_errors",           (
char*) &delayed_insert_errors,  SHOW_LONG},
 
 7887   {
"Delayed_insert_threads",   (
char*) &delayed_insert_threads, SHOW_LONG_NOFLUSH},
 
 7888   {
"Delayed_writes",           (
char*) &delayed_insert_writes,  SHOW_LONG},
 
 7889   {
"Flush_commands",           (
char*) &refresh_version,        SHOW_LONG_NOFLUSH},
 
 7890   {
"Handler_commit",           (
char*) offsetof(
STATUS_VAR, ha_commit_count), SHOW_LONGLONG_STATUS},
 
 7891   {
"Handler_delete",           (
char*) offsetof(
STATUS_VAR, ha_delete_count), SHOW_LONGLONG_STATUS},
 
 7892   {
"Handler_discover",         (
char*) offsetof(
STATUS_VAR, ha_discover_count), SHOW_LONGLONG_STATUS},
 
 7893   {
"Handler_external_lock",    (
char*) offsetof(
STATUS_VAR, ha_external_lock_count), SHOW_LONGLONG_STATUS},
 
 7894   {
"Handler_mrr_init",         (
char*) offsetof(
STATUS_VAR, ha_multi_range_read_init_count),  SHOW_LONGLONG_STATUS},
 
 7895   {
"Handler_prepare",          (
char*) offsetof(
STATUS_VAR, ha_prepare_count),  SHOW_LONGLONG_STATUS},
 
 7896   {
"Handler_read_first",       (
char*) offsetof(
STATUS_VAR, ha_read_first_count), SHOW_LONGLONG_STATUS},
 
 7897   {
"Handler_read_key",         (
char*) offsetof(
STATUS_VAR, ha_read_key_count), SHOW_LONGLONG_STATUS},
 
 7898   {
"Handler_read_last",        (
char*) offsetof(
STATUS_VAR, ha_read_last_count), SHOW_LONGLONG_STATUS},
 
 7899   {
"Handler_read_next",        (
char*) offsetof(
STATUS_VAR, ha_read_next_count), SHOW_LONGLONG_STATUS},
 
 7900   {
"Handler_read_prev",        (
char*) offsetof(
STATUS_VAR, ha_read_prev_count), SHOW_LONGLONG_STATUS},
 
 7901   {
"Handler_read_rnd",         (
char*) offsetof(
STATUS_VAR, ha_read_rnd_count), SHOW_LONGLONG_STATUS},
 
 7902   {
"Handler_read_rnd_next",    (
char*) offsetof(
STATUS_VAR, ha_read_rnd_next_count), SHOW_LONGLONG_STATUS},
 
 7903   {
"Handler_rollback",         (
char*) offsetof(
STATUS_VAR, ha_rollback_count), SHOW_LONGLONG_STATUS},
 
 7904   {
"Handler_savepoint",        (
char*) offsetof(
STATUS_VAR, ha_savepoint_count), SHOW_LONGLONG_STATUS},
 
 7905   {
"Handler_savepoint_rollback",(
char*) offsetof(
STATUS_VAR, ha_savepoint_rollback_count), SHOW_LONGLONG_STATUS},
 
 7906   {
"Handler_update",           (
char*) offsetof(
STATUS_VAR, ha_update_count), SHOW_LONGLONG_STATUS},
 
 7907   {
"Handler_write",            (
char*) offsetof(
STATUS_VAR, ha_write_count), SHOW_LONGLONG_STATUS},
 
 7908   {
"Key_blocks_not_flushed",   (
char*) offsetof(
KEY_CACHE, global_blocks_changed), SHOW_KEY_CACHE_LONG},
 
 7909   {
"Key_blocks_unused",        (
char*) offsetof(
KEY_CACHE, blocks_unused), SHOW_KEY_CACHE_LONG},
 
 7910   {
"Key_blocks_used",          (
char*) offsetof(
KEY_CACHE, blocks_used), SHOW_KEY_CACHE_LONG},
 
 7911   {
"Key_read_requests",        (
char*) offsetof(
KEY_CACHE, global_cache_r_requests), SHOW_KEY_CACHE_LONGLONG},
 
 7912   {
"Key_reads",                (
char*) offsetof(
KEY_CACHE, global_cache_read), SHOW_KEY_CACHE_LONGLONG},
 
 7913   {
"Key_write_requests",       (
char*) offsetof(
KEY_CACHE, global_cache_w_requests), SHOW_KEY_CACHE_LONGLONG},
 
 7914   {
"Key_writes",               (
char*) offsetof(
KEY_CACHE, global_cache_write), SHOW_KEY_CACHE_LONGLONG},
 
 7915   {
"Last_query_cost",          (
char*) offsetof(
STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
 
 7916   {
"Last_query_partial_plans", (
char*) offsetof(
STATUS_VAR, last_query_partial_plans), SHOW_LONGLONG_STATUS},
 
 7917   {
"Max_used_connections",     (
char*) &max_used_connections,  SHOW_LONG},
 
 7918   {
"Not_flushed_delayed_rows", (
char*) &delayed_rows_in_use,    SHOW_LONG_NOFLUSH},
 
 7919   {
"Open_files",               (
char*) &my_file_opened,         SHOW_LONG_NOFLUSH},
 
 7920   {
"Open_streams",             (
char*) &my_stream_opened,       SHOW_LONG_NOFLUSH},
 
 7921   {
"Open_table_definitions",   (
char*) &show_table_definitions, SHOW_FUNC},
 
 7922   {
"Open_tables",              (
char*) &show_open_tables,       SHOW_FUNC},
 
 7923   {
"Opened_files",             (
char*) &my_file_total_opened, SHOW_LONG_NOFLUSH},
 
 7924   {
"Opened_tables",            (
char*) offsetof(
STATUS_VAR, opened_tables), SHOW_LONGLONG_STATUS},
 
 7925   {
"Opened_table_definitions", (
char*) offsetof(
STATUS_VAR, opened_shares), SHOW_LONGLONG_STATUS},
 
 7926   {
"Prepared_stmt_count",      (
char*) &show_prepared_stmt_count, SHOW_FUNC},
 
 7927 #ifdef HAVE_QUERY_CACHE
 
 7928   {
"Qcache_free_blocks",       (
char*) &query_cache.free_memory_blocks, SHOW_LONG_NOFLUSH},
 
 7929   {
"Qcache_free_memory",       (
char*) &query_cache.free_memory, SHOW_LONG_NOFLUSH},
 
 7930   {
"Qcache_hits",              (
char*) &query_cache.hits,       SHOW_LONG},
 
 7931   {
"Qcache_inserts",           (
char*) &query_cache.inserts,    SHOW_LONG},
 
 7932   {
"Qcache_lowmem_prunes",     (
char*) &query_cache.lowmem_prunes, SHOW_LONG},
 
 7933   {
"Qcache_not_cached",        (
char*) &query_cache.refused,    SHOW_LONG},
 
 7934   {
"Qcache_queries_in_cache",  (
char*) &query_cache.queries_in_cache, SHOW_LONG_NOFLUSH},
 
 7935   {
"Qcache_total_blocks",      (
char*) &query_cache.total_blocks, SHOW_LONG_NOFLUSH},
 
 7937   {
"Queries",                  (
char*) &show_queries,            SHOW_FUNC},
 
 7938   {
"Questions",                (
char*) offsetof(
STATUS_VAR, questions), SHOW_LONGLONG_STATUS},
 
 7939   {
"Select_full_join",         (
char*) offsetof(
STATUS_VAR, select_full_join_count), SHOW_LONGLONG_STATUS},
 
 7940   {
"Select_full_range_join",   (
char*) offsetof(
STATUS_VAR, select_full_range_join_count), SHOW_LONGLONG_STATUS},
 
 7941   {
"Select_range",             (
char*) offsetof(
STATUS_VAR, select_range_count), SHOW_LONGLONG_STATUS},
 
 7942   {
"Select_range_check",       (
char*) offsetof(
STATUS_VAR, select_range_check_count), SHOW_LONGLONG_STATUS},
 
 7943   {
"Select_scan",              (
char*) offsetof(
STATUS_VAR, select_scan_count), SHOW_LONGLONG_STATUS},
 
 7944   {
"Slave_open_temp_tables",   (
char*) &slave_open_temp_tables, SHOW_INT},
 
 7945 #ifdef HAVE_REPLICATION
 
 7946   {
"Slave_retried_transactions",(
char*) &show_slave_retried_trans, SHOW_FUNC},
 
 7947   {
"Slave_heartbeat_period",   (
char*) &show_heartbeat_period, SHOW_FUNC},
 
 7948   {
"Slave_received_heartbeats",(
char*) &show_slave_received_heartbeats, SHOW_FUNC},
 
 7949   {
"Slave_last_heartbeat",     (
char*) &show_slave_last_heartbeat, SHOW_FUNC},
 
 7951   {
"Slave_rows_last_search_algorithm_used",(
char*) &show_slave_rows_last_search_algorithm_used, SHOW_FUNC},
 
 7953   {
"Slave_running",            (
char*) &show_slave_running,     SHOW_FUNC},
 
 7955   {
"Slow_launch_threads",      (
char*) &slow_launch_threads,    SHOW_LONG},
 
 7956   {
"Slow_queries",             (
char*) offsetof(
STATUS_VAR, long_query_count), SHOW_LONGLONG_STATUS},
 
 7957   {
"Sort_merge_passes",        (
char*) offsetof(
STATUS_VAR, filesort_merge_passes), SHOW_LONGLONG_STATUS},
 
 7958   {
"Sort_range",               (
char*) offsetof(
STATUS_VAR, filesort_range_count), SHOW_LONGLONG_STATUS},
 
 7959   {
"Sort_rows",                (
char*) offsetof(
STATUS_VAR, filesort_rows), SHOW_LONGLONG_STATUS},
 
 7960   {
"Sort_scan",                (
char*) offsetof(
STATUS_VAR, filesort_scan_count), SHOW_LONGLONG_STATUS},
 
 7962 #ifndef EMBEDDED_LIBRARY 
 7963   {
"Ssl_accept_renegotiates",  (
char*) &show_ssl_ctx_sess_accept_renegotiate, SHOW_FUNC},
 
 7964   {
"Ssl_accepts",              (
char*) &show_ssl_ctx_sess_accept, SHOW_FUNC},
 
 7965   {
"Ssl_callback_cache_hits",  (
char*) &show_ssl_ctx_sess_cb_hits, SHOW_FUNC},
 
 7966   {
"Ssl_cipher",               (
char*) &show_ssl_get_cipher, SHOW_FUNC},
 
 7967   {
"Ssl_cipher_list",          (
char*) &show_ssl_get_cipher_list, SHOW_FUNC},
 
 7968   {
"Ssl_client_connects",      (
char*) &show_ssl_ctx_sess_connect, SHOW_FUNC},
 
 7969   {
"Ssl_connect_renegotiates", (
char*) &show_ssl_ctx_sess_connect_renegotiate, SHOW_FUNC},
 
 7970   {
"Ssl_ctx_verify_depth",     (
char*) &show_ssl_ctx_get_verify_depth, SHOW_FUNC},
 
 7971   {
"Ssl_ctx_verify_mode",      (
char*) &show_ssl_ctx_get_verify_mode, SHOW_FUNC},
 
 7972   {
"Ssl_default_timeout",      (
char*) &show_ssl_get_default_timeout, SHOW_FUNC},
 
 7973   {
"Ssl_finished_accepts",     (
char*) &show_ssl_ctx_sess_accept_good, SHOW_FUNC},
 
 7974   {
"Ssl_finished_connects",    (
char*) &show_ssl_ctx_sess_connect_good, SHOW_FUNC},
 
 7975   {
"Ssl_session_cache_hits",   (
char*) &show_ssl_ctx_sess_hits, SHOW_FUNC},
 
 7976   {
"Ssl_session_cache_misses", (
char*) &show_ssl_ctx_sess_misses, SHOW_FUNC},
 
 7977   {
"Ssl_session_cache_mode",   (
char*) &show_ssl_ctx_get_session_cache_mode, SHOW_FUNC},
 
 7978   {
"Ssl_session_cache_overflows", (
char*) &show_ssl_ctx_sess_cache_full, SHOW_FUNC},
 
 7979   {
"Ssl_session_cache_size",   (
char*) &show_ssl_ctx_sess_get_cache_size, SHOW_FUNC},
 
 7980   {
"Ssl_session_cache_timeouts", (
char*) &show_ssl_ctx_sess_timeouts, SHOW_FUNC},
 
 7981   {
"Ssl_sessions_reused",      (
char*) &show_ssl_session_reused, SHOW_FUNC},
 
 7982   {
"Ssl_used_session_cache_entries",(
char*) &show_ssl_ctx_sess_number, SHOW_FUNC},
 
 7983   {
"Ssl_verify_depth",         (
char*) &show_ssl_get_verify_depth, SHOW_FUNC},
 
 7984   {
"Ssl_verify_mode",          (
char*) &show_ssl_get_verify_mode, SHOW_FUNC},
 
 7985   {
"Ssl_version",              (
char*) &show_ssl_get_version, SHOW_FUNC},
 
 7986   {
"Ssl_server_not_before",    (
char*) &show_ssl_get_server_not_before,
 
 7988   {
"Ssl_server_not_after",     (
char*) &show_ssl_get_server_not_after,
 
 7991   {
"Rsa_public_key",           (
char*) &show_rsa_public_key, SHOW_FUNC},
 
 7995   {
"Table_locks_immediate",    (
char*) &locks_immediate,        SHOW_LONG},
 
 7996   {
"Table_locks_waited",       (
char*) &locks_waited,           SHOW_LONG},
 
 7997   {
"Table_open_cache_hits",    (
char*) offsetof(
STATUS_VAR, table_open_cache_hits), SHOW_LONGLONG_STATUS},
 
 7998   {
"Table_open_cache_misses",  (
char*) offsetof(
STATUS_VAR, table_open_cache_misses), SHOW_LONGLONG_STATUS},
 
 7999   {
"Table_open_cache_overflows",(
char*) offsetof(
STATUS_VAR, table_open_cache_overflows), SHOW_LONGLONG_STATUS},
 
 8001   {
"Tc_log_max_pages_used",    (
char*) &tc_log_max_pages_used,  SHOW_LONG},
 
 8002   {
"Tc_log_page_size",         (
char*) &tc_log_page_size,       SHOW_LONG},
 
 8003   {
"Tc_log_page_waits",        (
char*) &tc_log_page_waits,      SHOW_LONG},
 
 8005   {
"Threads_cached",           (
char*) &blocked_pthread_count,    SHOW_LONG_NOFLUSH},
 
 8006   {
"Threads_connected",        (
char*) &connection_count,       SHOW_INT},
 
 8007   {
"Threads_created",        (
char*) &thread_created,   SHOW_LONG_NOFLUSH},
 
 8008   {
"Threads_running",          (
char*) &num_thread_running,     SHOW_INT},
 
 8009   {
"Uptime",                   (
char*) &show_starttime,         SHOW_FUNC},
 
 8010 #ifdef ENABLED_PROFILING
 
 8011   {
"Uptime_since_flush_status",(
char*) &show_flushstatustime,   SHOW_FUNC},
 
 8013   {NullS, NullS, SHOW_LONG}
 
 8016 void add_terminator(vector<my_option> *options)
 
 8019     {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0};
 
 8020   options->push_back(empty_element);
 
 8023 #ifndef EMBEDDED_LIBRARY 
 8024 static void print_version(
void)
 
 8026   set_server_version();
 
 8028   printf(
"%s  Ver %s for %s on %s (%s)\n",my_progname,
 
 8029    server_version,SYSTEM_TYPE,MACHINE_TYPE, MYSQL_COMPILATION_COMMENT);
 
 8035   const char *sa= a.
name;
 
 8036   const char *sb= b.
name;
 
 8037   for (; *sa || *sb; sa++, sb++)
 
 8041       if (*sa == 
'-' && *sb == 
'_')
 
 8048       if (*sa == 
'_' && *sb == 
'-')
 
 8058 static void print_help()
 
 8061   init_alloc_root(&mem_root, 4096, 4096);
 
 8063   all_options.pop_back();
 
 8064   sys_var_add_options(&all_options, sys_var::PARSE_EARLY);
 
 8065   for (
my_option *opt= my_long_early_options;
 
 8069     all_options.push_back(*opt);
 
 8071   add_plugin_options(&all_options, &mem_root);
 
 8072   std::sort(all_options.begin(), all_options.end(), std::less<my_option>());
 
 8073   add_terminator(&all_options);
 
 8075   my_print_help(&all_options[0]);
 
 8076   my_print_variables(&all_options[0]);
 
 8078   free_root(&mem_root, MYF(0));
 
 8079   vector<my_option>().swap(all_options);  
 
 8082 static void usage(
void)
 
 8084   DBUG_ENTER(
"usage");
 
 8085   if (!(default_charset_info= get_charset_by_csname(default_character_set_name,
 
 8089   if (!default_collation_name)
 
 8090     default_collation_name= (
char*) default_charset_info->name;
 
 8092   puts(ORACLE_WELCOME_COPYRIGHT_NOTICE(
"2000"));
 
 8093   puts(
"Starts the MySQL database server.\n");
 
 8094   printf(
"Usage: %s [OPTIONS]\n", my_progname);
 
 8096     puts(
"\nFor more help options (several pages), use mysqld --verbose --help.");
 
 8100   puts(
"NT and Win32 specific options:\n\ 
 8101   --install                     Install the default service (NT).\n\ 
 8102   --install-manual              Install the default service started manually (NT).\n\ 
 8103   --install service_name        Install an optional service (NT).\n\ 
 8104   --install-manual service_name Install an optional service started manually (NT).\n\ 
 8105   --remove                      Remove the default service from the service list (NT).\n\ 
 8106   --remove service_name         Remove the service_name from the service list (NT).\n\ 
 8107   --enable-named-pipe           Only to be used for the default server (NT).\n\ 
 8108   --standalone                  Dummy option to start as a standalone server (NT).\ 
 8112   print_defaults(MYSQL_CONFIG_NAME,load_default_groups);
 
 8119   if (! plugins_are_initialized)
 
 8122 Plugins have parameters that are not reflected in this list\n\ 
 8123 because execution stopped before plugins were initialized.");
 
 8127 To see what values a running MySQL server is using, type\n\ 
 8128 'mysqladmin variables' instead of 'mysqld --verbose --help'.");
 
 8147 static int mysql_init_variables(void) 
 8150   opt_skip_slave_start= opt_reckless_slave = 0;
 
 8151   mysql_home[0]= pidfile_name[0]= log_error_file[0]= 0;
 
 8152   myisam_test_invalid_symlink= test_if_data_home_dir;
 
 8153   opt_log= opt_slow_log= 0;
 
 8155   opt_disable_networking= opt_skip_show_db=0;
 
 8156   opt_skip_name_resolve= 0;
 
 8157   opt_ignore_builtin_innodb= 0;
 
 8158   opt_logname= opt_update_logname= opt_binlog_index_name= opt_slow_logname= 0;
 
 8159   opt_tc_log_file= (
char *)
"tc.log";      
 
 8161   opt_secure_file_priv= NULL;
 
 8164   kill_in_progress= 0;
 
 8166   server_id_supplied= 0;
 
 8167   test_flags= select_errors= dropping_tables= ha_open_options=0;
 
 8168   global_thread_count= num_thread_running= kill_blocked_pthreads_flag= wake_pthread=0;
 
 8169   slave_open_temp_tables= 0;
 
 8170   blocked_pthread_count= 0;
 
 8171   opt_endinfo= using_udf_functions= 0;
 
 8172   opt_using_transactions= 0;
 
 8173   abort_loop= select_thread_in_use= signal_thread_in_use= 0;
 
 8174   ready_to_exit= shutdown_in_progress= grant_option= 0;
 
 8175   aborted_threads= aborted_connects= 0;
 
 8176   delayed_insert_threads= delayed_insert_writes= delayed_rows_in_use= 0;
 
 8177   delayed_insert_errors= thread_created= 0;
 
 8179   binlog_cache_use=  binlog_cache_disk_use= 0;
 
 8180   max_used_connections= slow_launch_threads = 0;
 
 8181   mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0;
 
 8182   prepared_stmt_count= 0;
 
 8183   mysqld_unix_port= opt_mysql_tmpdir= my_bind_addr_str= NullS;
 
 8184   memset(&mysql_tmpdir_list, 0, 
sizeof(mysql_tmpdir_list));
 
 8185   memset(&global_status_var, 0, 
sizeof(global_status_var));
 
 8187   opt_super_large_pages= 0;
 
 8188 #if defined(ENABLED_DEBUG_SYNC) 
 8189   opt_debug_sync_timeout= 0;
 
 8191   key_map_full.set_all();
 
 8195   system_charset_info= &my_charset_utf8_general_ci;
 
 8196   files_charset_info= &my_charset_utf8_general_ci;
 
 8197   national_charset_info= &my_charset_utf8_general_ci;
 
 8198   table_alias_charset= &my_charset_bin;
 
 8199   character_set_filesystem= &my_charset_bin;
 
 8201   opt_specialflag= SPECIAL_ENGLISH;
 
 8204   mysql_home_ptr= mysql_home;
 
 8205   pidfile_name_ptr= pidfile_name;
 
 8206   log_error_file_ptr= log_error_file;
 
 8207   lc_messages_dir_ptr= lc_messages_dir;
 
 8208   protocol_version= PROTOCOL_VERSION;
 
 8209   what_to_log= ~ (1L << (uint) COM_TIME);
 
 8210   refresh_version= 1L;  
 
 8211   global_query_id= thread_id= 1L;
 
 8212   my_atomic_rwlock_init(&opt_binlog_max_flush_queue_time_lock);
 
 8213   my_atomic_rwlock_init(&global_query_id_lock);
 
 8214   my_atomic_rwlock_init(&thread_running_lock);
 
 8215   strmov(server_version, MYSQL_SERVER_VERSION);
 
 8216   global_thread_list= 
new std::set<THD*>;
 
 8217   waiting_thd_list= 
new std::list<THD*>;
 
 8219   if (!(dflt_key_cache= get_or_create_key_cache(default_key_cache_base.str,
 
 8220                                                 default_key_cache_base.length)))
 
 8222     sql_print_error(
"Cannot allocate the keycache");
 
 8226   multi_keycache_init();
 
 8229   mysql_real_data_home_len=
 
 8230     strmake(mysql_real_data_home, get_relative_path(MYSQL_DATADIR),
 
 8231             sizeof(mysql_real_data_home)-1) - mysql_real_data_home;
 
 8233   master_info_file= (
char*) 
"master.info",
 
 8234     relay_log_info_file= (
char*) 
"relay-log.info";
 
 8235   report_user= report_password = report_host= 0;  
 
 8236   opt_relay_logname= opt_relaylog_index_name= 0;
 
 8237   log_bin_basename= NULL;
 
 8238   log_bin_index= NULL;
 
 8245   default_character_set_name= (
char*) MYSQL_DEFAULT_CHARSET_NAME;
 
 8246   default_collation_name= compiled_default_collation_name;
 
 8247   character_set_filesystem_name= (
char*) 
"binary";
 
 8248   lc_messages= (
char*) 
"en_US";
 
 8249   lc_time_names_name= (
char*) 
"en_US";
 
 8253   default_dbug_option=IF_WIN(
"d:t:i:O,\\mysqld.trace",
 
 8254            "d:t:i:o,/tmp/mysqld.trace");
 
 8256   opt_error_log= IF_WIN(1,0);
 
 8257 #ifdef ENABLED_PROFILING 
 8258     have_profiling = SHOW_OPTION_YES;
 
 8260     have_profiling = SHOW_OPTION_NO;
 
 8264   have_ssl=SHOW_OPTION_YES;
 
 8266   have_ssl=SHOW_OPTION_NO;
 
 8268 #ifdef HAVE_BROKEN_REALPATH 
 8269   have_symlink=SHOW_OPTION_NO;
 
 8271   have_symlink=SHOW_OPTION_YES;
 
 8274   have_dlopen=SHOW_OPTION_YES;
 
 8276   have_dlopen=SHOW_OPTION_NO;
 
 8278 #ifdef HAVE_QUERY_CACHE 
 8279   have_query_cache=SHOW_OPTION_YES;
 
 8281   have_query_cache=SHOW_OPTION_NO;
 
 8284   have_geometry=SHOW_OPTION_YES;
 
 8286   have_geometry=SHOW_OPTION_NO;
 
 8288 #ifdef HAVE_RTREE_KEYS 
 8289   have_rtree_keys=SHOW_OPTION_YES;
 
 8291   have_rtree_keys=SHOW_OPTION_NO;
 
 8294   have_crypt=SHOW_OPTION_YES;
 
 8296   have_crypt=SHOW_OPTION_NO;
 
 8298 #ifdef HAVE_COMPRESS 
 8299   have_compress= SHOW_OPTION_YES;
 
 8301   have_compress= SHOW_OPTION_NO;
 
 8308 #ifndef EMBEDDED_LIBRARY 
 8313   shared_memory_base_name= default_shared_memory_base_name;
 
 8316 #if defined(__WIN__) 
 8319     char prg_dev[LIBLEN];
 
 8320     char executing_path_name[LIBLEN];
 
 8321     if (!test_if_hard_path(my_progname))
 
 8326       GetModuleFileName(NULL, executing_path_name, 
sizeof(executing_path_name));
 
 8327       my_path(prg_dev, executing_path_name, NULL);
 
 8330       my_path(prg_dev, my_progname, 
"mysql/bin");
 
 8331     strcat(prg_dev,
"/../");     
 
 8332     cleanup_dirname(mysql_home,prg_dev);
 
 8336   if (!(tmpenv = getenv(
"MY_BASEDIR_VERSION")))
 
 8337     tmpenv = DEFAULT_MYSQL_HOME;
 
 8338   (void) strmake(mysql_home, tmpenv, 
sizeof(mysql_home)-1);
 
 8344 mysqld_get_one_option(
int optid,
 
 8345                       const struct my_option *opt __attribute__((unused)),
 
 8351     DBUG_SET_INITIAL(argument ? argument : default_dbug_option);
 
 8356     global_system_variables.
sql_mode= MODE_ANSI;
 
 8357     global_system_variables.tx_isolation= ISO_SERIALIZABLE;
 
 8360     strmake(mysql_home,argument,
sizeof(mysql_home)-1);
 
 8363     if (default_collation_name == compiled_default_collation_name)
 
 8364       default_collation_name= 0;
 
 8367     strmake(mysql_real_data_home,argument, 
sizeof(mysql_real_data_home)-1);
 
 8369     mysql_real_data_home_ptr= mysql_real_data_home;
 
 8372     if (!mysqld_user || !strcmp(mysqld_user, argument))
 
 8373       mysqld_user= argument;
 
 8375       sql_print_warning(
"Ignoring user change to '%s' because the user was set to '%s' earlier on the command line\n", argument, mysqld_user);
 
 8378     WARN_DEPRECATED(NULL, 
"--language/-l", 
"'--lc-messages-dir'");
 
 8380   case OPT_LC_MESSAGES_DIRECTORY:
 
 8381     strmake(lc_messages_dir, argument, 
sizeof(lc_messages_dir)-1);
 
 8382     lc_messages_dir_ptr= lc_messages_dir;
 
 8384   case OPT_BINLOG_FORMAT:
 
 8385     binlog_format_used= 
true;
 
 8387 #include <sslopt-case.h> 
 8388 #ifndef EMBEDDED_LIBRARY 
 8396     else if (argument == disabled_my_option)
 
 8399       log_warnings= atoi(argument);
 
 8402     test_flags= argument ? (uint) atoi(argument) : 0;
 
 8405   case (
int) OPT_ISAM_LOG:
 
 8408   case (
int) OPT_BIN_LOG:
 
 8409     opt_bin_log= 
test(argument != disabled_my_option);
 
 8411 #ifdef HAVE_REPLICATION 
 8412   case (
int)OPT_REPLICATE_IGNORE_DB:
 
 8414     rpl_filter->add_ignore_db(argument);
 
 8417   case (
int)OPT_REPLICATE_DO_DB:
 
 8419     rpl_filter->add_do_db(argument);
 
 8422   case (
int)OPT_REPLICATE_REWRITE_DB:
 
 8424     char* key = argument,*p, *val;
 
 8426     if (!(p= strstr(argument, 
"->")))
 
 8428       sql_print_error(
"Bad syntax in replicate-rewrite-db - missing '->'!\n");
 
 8432     while(p > argument && my_isspace(mysqld_charset, p[-1]))
 
 8437       sql_print_error(
"Bad syntax in replicate-rewrite-db - empty FROM db!\n");
 
 8440     while (*val && my_isspace(mysqld_charset, *val))
 
 8444       sql_print_error(
"Bad syntax in replicate-rewrite-db - empty TO db!\n");
 
 8448     rpl_filter->add_db_rewrite(key, val);
 
 8452   case (
int)OPT_BINLOG_IGNORE_DB:
 
 8454     binlog_filter->add_ignore_db(argument);
 
 8457   case (
int)OPT_BINLOG_DO_DB:
 
 8459     binlog_filter->add_do_db(argument);
 
 8462   case (
int)OPT_REPLICATE_DO_TABLE:
 
 8464     if (rpl_filter->add_do_table_array(argument))
 
 8466       sql_print_error(
"Could not add do table rule '%s'!\n", argument);
 
 8471   case (
int)OPT_REPLICATE_WILD_DO_TABLE:
 
 8473     if (rpl_filter->add_wild_do_table(argument))
 
 8475       sql_print_error(
"Could not add do table rule '%s'!\n", argument);
 
 8480   case (
int)OPT_REPLICATE_WILD_IGNORE_TABLE:
 
 8482     if (rpl_filter->add_wild_ignore_table(argument))
 
 8484       sql_print_error(
"Could not add ignore table rule '%s'!\n", argument);
 
 8489   case (
int)OPT_REPLICATE_IGNORE_TABLE:
 
 8491     if (rpl_filter->add_ignore_table_array(argument))
 
 8493       sql_print_error(
"Could not add ignore table rule '%s'!\n", argument);
 
 8499   case (
int) OPT_MASTER_RETRY_COUNT:
 
 8500     WARN_DEPRECATED(NULL, 
"--master-retry-count", 
"'CHANGE MASTER TO master_retry_count = <num>'");
 
 8502   case (
int) OPT_SKIP_NEW:
 
 8503     opt_specialflag|= SPECIAL_NO_NEW_FUNC;
 
 8504     delay_key_write_options= DELAY_KEY_WRITE_NONE;
 
 8505     myisam_concurrent_insert=0;
 
 8506     myisam_recover_options= HA_RECOVER_OFF;
 
 8507     sp_automatic_privileges=0;
 
 8509     ha_open_options&= ~(HA_OPEN_ABORT_IF_CRASHED | HA_OPEN_DELAY_KEY_WRITE);
 
 8510 #ifdef HAVE_QUERY_CACHE 
 8514   case (
int) OPT_SKIP_HOST_CACHE:
 
 8515     opt_specialflag|= SPECIAL_NO_HOST_CACHE;
 
 8517   case (
int) OPT_SKIP_RESOLVE:
 
 8518     opt_skip_name_resolve= 1;
 
 8519     opt_specialflag|=SPECIAL_NO_RESOLVE;
 
 8521   case (
int) OPT_WANT_CORE:
 
 8522     test_flags |= TEST_CORE_ON_SIGNAL;
 
 8524   case (
int) OPT_SKIP_STACK_TRACE:
 
 8525     test_flags|=TEST_NO_STACKTRACE;
 
 8535     server_id_supplied = 1;
 
 8537   case OPT_LOWER_CASE_TABLE_NAMES:
 
 8538     lower_case_table_names_used= 1;
 
 8540 #if defined(ENABLED_DEBUG_SYNC) 
 8541   case OPT_DEBUG_SYNC_TIMEOUT:
 
 8551       opt_debug_sync_timeout= DEBUG_SYNC_DEFAULT_WAIT_TIMEOUT;
 
 8556   case OPT_ENGINE_CONDITION_PUSHDOWN:
 
 8561     if (global_system_variables.engine_condition_pushdown)
 
 8562       global_system_variables.optimizer_switch|=
 
 8563         OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN;
 
 8565       global_system_variables.optimizer_switch&=
 
 8566         ~OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN;
 
 8573     if (argument == NULL) 
 
 8574       log_error_file_ptr= 
const_cast<char*
>(
"");
 
 8577   case OPT_IGNORE_DB_DIRECTORY:
 
 8579       ignore_db_dirs_reset();
 
 8582       if (push_ignored_db_dir(argument))
 
 8584         sql_print_error(
"Can't start server: " 
 8585                         "cannot process --ignore-db-dir=%.*s", 
 
 8586                         FN_REFLEN, argument);
 
 8593   case OPT_PLUGIN_LOAD:
 
 8594     free_list(opt_plugin_load_list_ptr);
 
 8596   case OPT_PLUGIN_LOAD_ADD:
 
 8599   case OPT_DEFAULT_AUTH:
 
 8600     if (set_default_auth_plugin(argument, strlen(argument)))
 
 8602       sql_print_error(
"Can't start server: " 
 8603                       "Invalid value for --default-authentication-plugin");
 
 8607   case OPT_SECURE_AUTH:
 
 8608     if (opt_secure_auth == 0)
 
 8609       WARN_DEPRECATED(NULL, 
"pre-4.1 password hash", 
"post-4.1 password hash");
 
 8611   case OPT_PFS_INSTRUMENT:
 
 8613 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE 
 8614 #ifndef EMBEDDED_LIBRARY 
 8627       char *name= argument,*p= NULL, *val= NULL;
 
 8628       my_bool quote= 
false; 
 
 8629       my_bool error= 
true;  
 
 8630       const int PFS_BUFFER_SIZE= 128;
 
 8631       char orig_argument[PFS_BUFFER_SIZE+1];
 
 8632       orig_argument[0]= 0;
 
 8638       strncpy(orig_argument, argument, PFS_BUFFER_SIZE);
 
 8641       if (!(p= strchr(argument, 
'=')))
 
 8650       while (*name && (my_isspace(mysqld_charset, *name) || (*name == 
'\'')))
 
 8664       while ((p > name) && my_isspace(mysqld_charset, p[-1]))
 
 8669       if (p > name && (p[-1] == 
'/'))
 
 8676       while (*val && my_isspace(mysqld_charset, *val))
 
 8680       p= val + strlen(val);
 
 8681       while (p > val && (my_isspace(mysqld_charset, p[-1]) || p[-1] == 
'\''))
 
 8708         my_getopt_error_reporter(WARNING_LEVEL,
 
 8709                                  "Invalid instrument name or value for " 
 8710                                  "performance_schema_instrument '%s'",
 
 8718   case OPT_THREAD_CACHE_SIZE:
 
 8719     thread_cache_size_specified= 
true;
 
 8721   case OPT_HOST_CACHE_SIZE:
 
 8722     host_cache_size_specified= 
true;
 
 8724   case OPT_TABLE_DEFINITION_CACHE:
 
 8725     table_definition_cache_specified= 
true;
 
 8737 mysql_getopt_value(
const char *keyname, uint key_length,
 
 8742   switch (option->
id) {
 
 8743   case OPT_KEY_BUFFER_SIZE:
 
 8744   case OPT_KEY_CACHE_BLOCK_SIZE:
 
 8745   case OPT_KEY_CACHE_DIVISION_LIMIT:
 
 8746   case OPT_KEY_CACHE_AGE_THRESHOLD:
 
 8749     if (!(key_cache= get_or_create_key_cache(keyname, key_length)))
 
 8752         *error= EXIT_OUT_OF_MEMORY;
 
 8755     switch (option->
id) {
 
 8756     case OPT_KEY_BUFFER_SIZE:
 
 8757       return &key_cache->param_buff_size;
 
 8758     case OPT_KEY_CACHE_BLOCK_SIZE:
 
 8759       return &key_cache->param_block_size;
 
 8760     case OPT_KEY_CACHE_DIVISION_LIMIT:
 
 8761       return &key_cache->param_division_limit;
 
 8762     case OPT_KEY_CACHE_AGE_THRESHOLD:
 
 8763       return &key_cache->param_age_threshold;
 
 8767   return option->
value;
 
 8770 static void option_error_reporter(
enum loglevel level, 
const char *format, ...)
 
 8773   va_start(args, format);
 
 8776   if (level == ERROR_LEVEL || !opt_bootstrap ||
 
 8796 static int get_options(
int *argc_ptr, 
char ***argv_ptr)
 
 8800   my_getopt_register_get_addr(mysql_getopt_value);
 
 8801   my_getopt_error_reporter= option_error_reporter;
 
 8804   all_options.reserve(array_elements(my_long_options));
 
 8806        opt < my_long_options + array_elements(my_long_options) - 1;
 
 8809     all_options.push_back(*opt);
 
 8811   sys_var_add_options(&all_options, sys_var::PARSE_NORMAL);
 
 8812   add_terminator(&all_options);
 
 8815   my_getopt_skip_unknown= TRUE;
 
 8817   if ((ho_error= handle_options(argc_ptr, argv_ptr, &all_options[0],
 
 8818                                 mysqld_get_one_option)))
 
 8822     vector<my_option>().swap(all_options);  
 
 8835   if ((opt_log_slow_admin_statements || opt_log_queries_not_using_indexes ||
 
 8836        opt_log_slow_slave_statements) &&
 
 8838     sql_print_warning(
"options --log-slow-admin-statements, " 
 8839                       "--log-queries-not-using-indexes and " 
 8840                       "--log-slow-slave-statements have no effect if " 
 8841                       "--slow-query-log is not set");
 
 8842   if (global_system_variables.net_buffer_length >
 
 8843       global_system_variables.max_allowed_packet)
 
 8845     sql_print_warning(
"net_buffer_length (%lu) is set to be larger " 
 8846                       "than max_allowed_packet (%lu). Please rectify.",
 
 8847                       global_system_variables.net_buffer_length,
 
 8848                       global_system_variables.max_allowed_packet);
 
 8856   if (!opt_help && !global_system_variables.explicit_defaults_for_timestamp)
 
 8857     sql_print_warning(
"TIMESTAMP with implicit DEFAULT value is deprecated. " 
 8858                       "Please use --explicit_defaults_for_timestamp server " 
 8859                       "option (see documentation for more details).");
 
 8862   if (log_error_file_ptr != disabled_my_option)
 
 8865     log_error_file_ptr= 
const_cast<char*
>(
"");
 
 8867   opt_init_connect.length=strlen(opt_init_connect.str);
 
 8868   opt_init_slave.length=strlen(opt_init_slave.str);
 
 8870   if (global_system_variables.low_priority_updates)
 
 8871     thr_upgraded_concurrent_insert_lock= TL_WRITE_LOW_PRIORITY;
 
 8873   if (ft_boolean_check_syntax_string((uchar*) ft_boolean_syntax))
 
 8875     sql_print_error(
"Invalid ft-boolean-syntax string: %s\n",
 
 8880   if (opt_disable_networking)
 
 8883   if (opt_skip_show_db)
 
 8884     opt_specialflag|= SPECIAL_SKIP_SHOW_DB;
 
 8889 #ifdef HAVE_REPLICATION 
 8890   if (opt_slave_skip_errors)
 
 8891     add_slave_skip_errors(opt_slave_skip_errors);
 
 8894   if (global_system_variables.max_join_size == HA_POS_ERROR)
 
 8895     global_system_variables.
option_bits|= OPTION_BIG_SELECTS;
 
 8897     global_system_variables.
option_bits&= ~OPTION_BIG_SELECTS;
 
 8900   const ulonglong turn_bit_on= opt_autocommit ?
 
 8907     expand_sql_mode(global_system_variables.
sql_mode);
 
 8908 #if defined(HAVE_BROKEN_REALPATH) 
 8910   my_disable_symlinks=1;
 
 8911   have_symlink=SHOW_OPTION_NO;
 
 8915     my_disable_symlinks=1;
 
 8916     have_symlink=SHOW_OPTION_DISABLED;
 
 8922     test_flags|= TEST_SIGINT | TEST_NO_STACKTRACE;
 
 8923     test_flags&= ~TEST_CORE_ON_SIGNAL;
 
 8928 #ifndef EMBEDDED_LIBRARY 
 8930     set_root(mysqld_chroot);
 
 8932   thread_handling = SCHEDULER_NO_THREADS;
 
 8933   max_allowed_packet= global_system_variables.max_allowed_packet;
 
 8934   net_buffer_length= global_system_variables.net_buffer_length;
 
 8943   my_disable_locking= myisam_single_user= 
test(opt_external_locking == 0);
 
 8944   my_default_record_cache_size=global_system_variables.read_buff_size;
 
 8946   global_system_variables.long_query_time= (ulonglong)
 
 8947     (global_system_variables.long_query_time_double * 1e6);
 
 8949   if (opt_short_log_format)
 
 8950     opt_specialflag|= SPECIAL_SHORT_LOG_FORMAT;
 
 8952   if (init_global_datetime_format(MYSQL_TIMESTAMP_DATE,
 
 8953                                   &global_date_format) ||
 
 8954       init_global_datetime_format(MYSQL_TIMESTAMP_TIME,
 
 8955                                   &global_time_format) ||
 
 8956       init_global_datetime_format(MYSQL_TIMESTAMP_DATETIME,
 
 8957                                   &global_datetime_format))
 
 8960 #ifdef EMBEDDED_LIBRARY 
 8961   one_thread_scheduler();
 
 8963   if (thread_handling <= SCHEDULER_ONE_THREAD_PER_CONNECTION)
 
 8964     one_thread_per_connection_scheduler();
 
 8966     one_thread_scheduler();
 
 8969   global_system_variables.engine_condition_pushdown=
 
 8970     test(global_system_variables.optimizer_switch &
 
 8971          OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN);
 
 8973   opt_readonly= read_only;
 
 8986 static void set_server_version(
void)
 
 8988   char *end= strxmov(server_version, MYSQL_SERVER_VERSION,
 
 8989                      MYSQL_SERVER_SUFFIX_STR, NullS);
 
 8990 #ifdef EMBEDDED_LIBRARY 
 8991   end= strmov(end, 
"-embedded");
 
 8994   if (!strstr(MYSQL_SERVER_SUFFIX_STR, 
"-debug"))
 
 8995     end= strmov(end, 
"-debug");
 
 8997   if (opt_log || opt_slow_log || opt_bin_log)
 
 8998     strmov(end, 
"-log");                        
 
 9002 static char *get_relative_path(
const char *path)
 
 9004   if (test_if_hard_path(path) &&
 
 9005       is_prefix(path,DEFAULT_MYSQL_HOME) &&
 
 9006       strcmp(DEFAULT_MYSQL_HOME,FN_ROOTDIR))
 
 9008     path+=(uint) strlen(DEFAULT_MYSQL_HOME);
 
 9009     while (*path == FN_LIBCHAR || *path == FN_LIBCHAR2)
 
 9012   return (
char*) path;
 
 9024 fn_format_relative_to_data_home(
char * to, 
const char *name,
 
 9025         const char *dir, 
const char *extension)
 
 9027   char tmp_path[FN_REFLEN];
 
 9028   if (!test_if_hard_path(dir))
 
 9030     strxnmov(tmp_path,
sizeof(tmp_path)-1, mysql_real_data_home,
 
 9034   return !fn_format(to, name, dir, extension,
 
 9035         MY_APPEND_EXT | MY_UNPACK_FILENAME | MY_SAFE_PATH);
 
 9050 bool is_secure_file_path(
char *path)
 
 9052   char buff1[FN_REFLEN], buff2[FN_REFLEN];
 
 9053   size_t opt_secure_file_priv_len;
 
 9057   if (!opt_secure_file_priv)
 
 9060   opt_secure_file_priv_len= strlen(opt_secure_file_priv);
 
 9062   if (strlen(path) >= FN_REFLEN)
 
 9065   if (my_realpath(buff1, path, 0))
 
 9070     int length= (int)dirname_length(path);
 
 9071     if (length >= FN_REFLEN)
 
 9073     memcpy(buff2, path, length);
 
 9074     buff2[length]= 
'\0';
 
 9075     if (length == 0 || my_realpath(buff1, buff2, 0))
 
 9078   convert_dirname(buff2, buff1, NullS);
 
 9079   if (!lower_case_file_system)
 
 9081     if (strncmp(opt_secure_file_priv, buff2, opt_secure_file_priv_len))
 
 9086     if (files_charset_info->coll->strnncoll(files_charset_info,
 
 9087                                             (uchar *) buff2, strlen(buff2),
 
 9088                                             (uchar *) opt_secure_file_priv,
 
 9089                                             opt_secure_file_priv_len,
 
 9097 static int fix_paths(
void)
 
 9099   char buff[FN_REFLEN],*pos;
 
 9100   convert_dirname(mysql_home,mysql_home,NullS);
 
 9102   my_realpath(mysql_home,mysql_home,MYF(0));
 
 9104   pos=strend(mysql_home);
 
 9105   if (pos[-1] != FN_LIBCHAR)
 
 9110   convert_dirname(lc_messages_dir, lc_messages_dir, NullS);
 
 9111   convert_dirname(mysql_real_data_home,mysql_real_data_home,NullS);
 
 9112   (void) my_load_path(mysql_home,mysql_home,
""); 
 
 9113   (void) my_load_path(mysql_real_data_home,mysql_real_data_home,mysql_home);
 
 9114   (void) my_load_path(pidfile_name, pidfile_name_ptr, mysql_real_data_home);
 
 9116   convert_dirname(opt_plugin_dir, opt_plugin_dir_ptr ? opt_plugin_dir_ptr : 
 
 9117                                   get_relative_path(PLUGINDIR), NullS);
 
 9118   (void) my_load_path(opt_plugin_dir, opt_plugin_dir, mysql_home);
 
 9119   opt_plugin_dir_ptr= opt_plugin_dir;
 
 9121   my_realpath(mysql_unpacked_real_data_home, mysql_real_data_home, MYF(0));
 
 9122   mysql_unpacked_real_data_home_len=
 
 9123     (int) strlen(mysql_unpacked_real_data_home);
 
 9124   if (mysql_unpacked_real_data_home[mysql_unpacked_real_data_home_len-1] == FN_LIBCHAR)
 
 9125     --mysql_unpacked_real_data_home_len;
 
 9127   char *sharedir=get_relative_path(SHAREDIR);
 
 9128   if (test_if_hard_path(sharedir))
 
 9129     strmake(buff,sharedir,
sizeof(buff)-1);    
 
 9131     strxnmov(buff,
sizeof(buff)-1,mysql_home,sharedir,NullS);
 
 9132   convert_dirname(buff,buff,NullS);
 
 9133   (void) my_load_path(lc_messages_dir, lc_messages_dir, buff);
 
 9137     strmake(mysql_charsets_dir, charsets_dir, 
sizeof(mysql_charsets_dir)-1);
 
 9139     strxnmov(mysql_charsets_dir, 
sizeof(mysql_charsets_dir)-1, buff,
 
 9140        CHARSET_DIR, NullS);
 
 9141   (void) my_load_path(mysql_charsets_dir, mysql_charsets_dir, buff);
 
 9142   convert_dirname(mysql_charsets_dir, mysql_charsets_dir, NullS);
 
 9143   charsets_dir=mysql_charsets_dir;
 
 9145   if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir))
 
 9147   if (!opt_mysql_tmpdir)
 
 9148     opt_mysql_tmpdir= mysql_tmpdir;
 
 9149 #ifdef HAVE_REPLICATION 
 9150   if (!slave_load_tmpdir)
 
 9151     slave_load_tmpdir= mysql_tmpdir;
 
 9157   if (opt_secure_file_priv)
 
 9159     if (*opt_secure_file_priv == 0)
 
 9160       opt_secure_file_priv= NULL;
 
 9163       if (strlen(opt_secure_file_priv) >= FN_REFLEN)
 
 9164         opt_secure_file_priv[FN_REFLEN-1]= 
'\0';
 
 9165       if (my_realpath(buff, opt_secure_file_priv, 0))
 
 9167         sql_print_warning(
"Failed to normalize the argument for --secure-file-priv.");
 
 9170       convert_dirname(secure_file_real_path, buff, NullS);
 
 9171       opt_secure_file_priv= secure_file_real_path;
 
 9191 static int test_if_case_insensitive(
const char *dir_name)
 
 9195   char buff[FN_REFLEN], buff2[FN_REFLEN];
 
 9197   DBUG_ENTER(
"test_if_case_insensitive");
 
 9199   fn_format(buff, glob_hostname, dir_name, 
".lower-test",
 
 9200       MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
 
 9201   fn_format(buff2, glob_hostname, dir_name, 
".LOWER-TEST",
 
 9202       MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
 
 9205                                buff, 0666, O_RDWR, MYF(0))) < 0)
 
 9207     sql_print_warning(
"Can't create test file %s", buff);
 
 9214   DBUG_PRINT(
"exit", (
"result: %d", result));
 
 9215   DBUG_RETURN(result);
 
 9219 #ifndef EMBEDDED_LIBRARY 
 9224 static void create_pid_file()
 
 9228                                O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0)
 
 9230     char buff[MAX_BIGINT_WIDTH + 1], *end;
 
 9231     end= int10_to_str((
long) getpid(), buff, 10);
 
 9234                           MYF(MY_WME | MY_NABP)))
 
 9237       pid_file_created= 
true;
 
 9242   sql_perror(
"Can't start server: can't create PID file");
 
 9254 static void delete_pid_file(myf 
flags)
 
 9256 #ifndef EMBEDDED_LIBRARY 
 9258   if (opt_bootstrap ||
 
 9259       !pid_file_created ||
 
 9265   uchar buff[MAX_BIGINT_WIDTH + 1];
 
 9268   buff[
sizeof(buff) - 1]= 
'\0'; 
 
 9269   if (error != MY_FILE_ERROR &&
 
 9270       atol((
char *) buff) == (long) getpid())
 
 9273     pid_file_created= 
false;
 
 9281 void refresh_status(THD *thd)
 
 9286   add_to_status(&global_status_var, &thd->status_var);
 
 9289   memset(&thd->status_var, 0, 
sizeof(thd->status_var));
 
 9292   reset_status_vars();
 
 9295   process_key_caches(reset_key_cache_counters);
 
 9296   flush_status_time= time((time_t*) 0);
 
 9306   max_used_connections= get_thread_count() - delayed_insert_threads;
 
 9316 #ifdef HAVE_PSI_INTERFACE 
 9318 PSI_mutex_key key_PAGE_lock, key_LOCK_sync, key_LOCK_active, key_LOCK_pool;
 
 9322 PSI_mutex_key key_LOCK_des_key_file;
 
 9325 PSI_mutex_key key_BINLOG_LOCK_commit;
 
 9326 PSI_mutex_key key_BINLOG_LOCK_commit_queue;
 
 9327 PSI_mutex_key key_BINLOG_LOCK_done;
 
 9328 PSI_mutex_key key_BINLOG_LOCK_flush_queue;
 
 9329 PSI_mutex_key key_BINLOG_LOCK_index;
 
 9330 PSI_mutex_key key_BINLOG_LOCK_log;
 
 9331 PSI_mutex_key key_BINLOG_LOCK_sync;
 
 9332 PSI_mutex_key key_BINLOG_LOCK_sync_queue;
 
 9333 PSI_mutex_key key_BINLOG_LOCK_xids;
 
 9335   key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi,
 
 9336   key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create,
 
 9337   key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log,
 
 9338   key_LOCK_gdl, key_LOCK_global_system_variables,
 
 9340   key_LOCK_prepared_stmt_count,
 
 9341   key_LOCK_sql_slave_skip_counter,
 
 9342   key_LOCK_slave_net_timeout,
 
 9343   key_LOCK_server_started, key_LOCK_status,
 
 9344   key_LOCK_system_variables_hash, key_LOCK_table_share, key_LOCK_thd_data,
 
 9345   key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log,
 
 9346   key_master_info_data_lock, key_master_info_run_lock,
 
 9347   key_master_info_sleep_lock,
 
 9348   key_mutex_slave_reporting_capability_err_lock, key_relay_log_info_data_lock,
 
 9349   key_relay_log_info_sleep_lock,
 
 9350   key_relay_log_info_log_space_lock, key_relay_log_info_run_lock,
 
 9351   key_mutex_slave_parallel_pend_jobs, key_mutex_mts_temp_tables_lock,
 
 9352   key_mutex_slave_parallel_worker,
 
 9353   key_structure_guard_mutex, key_TABLE_SHARE_LOCK_ha_data,
 
 9354   key_LOCK_error_messages, key_LOG_INFO_lock, key_LOCK_thread_count,
 
 9355   key_LOCK_log_throttle_qni;
 
 9356 PSI_mutex_key key_RELAYLOG_LOCK_commit;
 
 9357 PSI_mutex_key key_RELAYLOG_LOCK_commit_queue;
 
 9358 PSI_mutex_key key_RELAYLOG_LOCK_done;
 
 9359 PSI_mutex_key key_RELAYLOG_LOCK_flush_queue;
 
 9360 PSI_mutex_key key_RELAYLOG_LOCK_index;
 
 9361 PSI_mutex_key key_RELAYLOG_LOCK_log;
 
 9362 PSI_mutex_key key_RELAYLOG_LOCK_sync;
 
 9363 PSI_mutex_key key_RELAYLOG_LOCK_sync_queue;
 
 9364 PSI_mutex_key key_RELAYLOG_LOCK_xids;
 
 9365 PSI_mutex_key key_LOCK_sql_rand;
 
 9366 PSI_mutex_key key_gtid_ensure_index_mutex;
 
 9367 PSI_mutex_key key_LOCK_thread_created;
 
 9369 static PSI_mutex_info all_server_mutexes[]=
 
 9372   { &key_PAGE_lock, 
"PAGE::lock", 0},
 
 9373   { &key_LOCK_sync, 
"TC_LOG_MMAP::LOCK_sync", 0},
 
 9374   { &key_LOCK_active, 
"TC_LOG_MMAP::LOCK_active", 0},
 
 9375   { &key_LOCK_pool, 
"TC_LOG_MMAP::LOCK_pool", 0},
 
 9379   { &key_LOCK_des_key_file, 
"LOCK_des_key_file", PSI_FLAG_GLOBAL},
 
 9382   { &key_BINLOG_LOCK_commit, 
"MYSQL_BIN_LOG::LOCK_commit", 0 },
 
 9383   { &key_BINLOG_LOCK_commit_queue, 
"MYSQL_BIN_LOG::LOCK_commit_queue", 0 },
 
 9384   { &key_BINLOG_LOCK_done, 
"MYSQL_BIN_LOG::LOCK_done", 0 },
 
 9385   { &key_BINLOG_LOCK_flush_queue, 
"MYSQL_BIN_LOG::LOCK_flush_queue", 0 },
 
 9386   { &key_BINLOG_LOCK_index, 
"MYSQL_BIN_LOG::LOCK_index", 0},
 
 9387   { &key_BINLOG_LOCK_log, 
"MYSQL_BIN_LOG::LOCK_log", 0},
 
 9388   { &key_BINLOG_LOCK_sync, 
"MYSQL_BIN_LOG::LOCK_sync", 0},
 
 9389   { &key_BINLOG_LOCK_sync_queue, 
"MYSQL_BIN_LOG::LOCK_sync_queue", 0 },
 
 9390   { &key_BINLOG_LOCK_xids, 
"MYSQL_BIN_LOG::LOCK_xids", 0 },
 
 9391   { &key_RELAYLOG_LOCK_commit, 
"MYSQL_RELAY_LOG::LOCK_commit", 0},
 
 9392   { &key_RELAYLOG_LOCK_commit_queue, 
"MYSQL_RELAY_LOG::LOCK_commit_queue", 0 },
 
 9393   { &key_RELAYLOG_LOCK_done, 
"MYSQL_RELAY_LOG::LOCK_done", 0 },
 
 9394   { &key_RELAYLOG_LOCK_flush_queue, 
"MYSQL_RELAY_LOG::LOCK_flush_queue", 0 },
 
 9395   { &key_RELAYLOG_LOCK_index, 
"MYSQL_RELAY_LOG::LOCK_index", 0},
 
 9396   { &key_RELAYLOG_LOCK_log, 
"MYSQL_RELAY_LOG::LOCK_log", 0},
 
 9397   { &key_RELAYLOG_LOCK_sync, 
"MYSQL_RELAY_LOG::LOCK_sync", 0},
 
 9398   { &key_RELAYLOG_LOCK_sync_queue, 
"MYSQL_RELAY_LOG::LOCK_sync_queue", 0 },
 
 9399   { &key_RELAYLOG_LOCK_xids, 
"MYSQL_RELAY_LOG::LOCK_xids", 0},
 
 9400   { &key_delayed_insert_mutex, 
"Delayed_insert::mutex", 0},
 
 9401   { &key_hash_filo_lock, 
"hash_filo::lock", 0},
 
 9402   { &key_LOCK_active_mi, 
"LOCK_active_mi", PSI_FLAG_GLOBAL},
 
 9403   { &key_LOCK_connection_count, 
"LOCK_connection_count", PSI_FLAG_GLOBAL},
 
 9404   { &key_LOCK_crypt, 
"LOCK_crypt", PSI_FLAG_GLOBAL},
 
 9405   { &key_LOCK_delayed_create, 
"LOCK_delayed_create", PSI_FLAG_GLOBAL},
 
 9406   { &key_LOCK_delayed_insert, 
"LOCK_delayed_insert", PSI_FLAG_GLOBAL},
 
 9407   { &key_LOCK_delayed_status, 
"LOCK_delayed_status", PSI_FLAG_GLOBAL},
 
 9408   { &key_LOCK_error_log, 
"LOCK_error_log", PSI_FLAG_GLOBAL},
 
 9409   { &key_LOCK_gdl, 
"LOCK_gdl", PSI_FLAG_GLOBAL},
 
 9410   { &key_LOCK_global_system_variables, 
"LOCK_global_system_variables", PSI_FLAG_GLOBAL},
 
 9411   { &key_LOCK_manager, 
"LOCK_manager", PSI_FLAG_GLOBAL},
 
 9412   { &key_LOCK_prepared_stmt_count, 
"LOCK_prepared_stmt_count", PSI_FLAG_GLOBAL},
 
 9413   { &key_LOCK_sql_slave_skip_counter, 
"LOCK_sql_slave_skip_counter", PSI_FLAG_GLOBAL},
 
 9414   { &key_LOCK_slave_net_timeout, 
"LOCK_slave_net_timeout", PSI_FLAG_GLOBAL},
 
 9415   { &key_LOCK_server_started, 
"LOCK_server_started", PSI_FLAG_GLOBAL},
 
 9416   { &key_LOCK_status, 
"LOCK_status", PSI_FLAG_GLOBAL},
 
 9417   { &key_LOCK_system_variables_hash, 
"LOCK_system_variables_hash", PSI_FLAG_GLOBAL},
 
 9418   { &key_LOCK_table_share, 
"LOCK_table_share", PSI_FLAG_GLOBAL},
 
 9419   { &key_LOCK_thd_data, 
"THD::LOCK_thd_data", 0},
 
 9420   { &key_LOCK_user_conn, 
"LOCK_user_conn", PSI_FLAG_GLOBAL},
 
 9421   { &key_LOCK_uuid_generator, 
"LOCK_uuid_generator", PSI_FLAG_GLOBAL},
 
 9422   { &key_LOCK_sql_rand, 
"LOCK_sql_rand", PSI_FLAG_GLOBAL},
 
 9423   { &key_LOG_LOCK_log, 
"LOG::LOCK_log", 0},
 
 9424   { &key_master_info_data_lock, 
"Master_info::data_lock", 0},
 
 9425   { &key_master_info_run_lock, 
"Master_info::run_lock", 0},
 
 9426   { &key_master_info_sleep_lock, 
"Master_info::sleep_lock", 0},
 
 9427   { &key_mutex_slave_reporting_capability_err_lock, 
"Slave_reporting_capability::err_lock", 0},
 
 9428   { &key_relay_log_info_data_lock, 
"Relay_log_info::data_lock", 0},
 
 9429   { &key_relay_log_info_sleep_lock, 
"Relay_log_info::sleep_lock", 0},
 
 9430   { &key_relay_log_info_log_space_lock, 
"Relay_log_info::log_space_lock", 0},
 
 9431   { &key_relay_log_info_run_lock, 
"Relay_log_info::run_lock", 0},
 
 9432   { &key_mutex_slave_parallel_pend_jobs, 
"Relay_log_info::pending_jobs_lock", 0},
 
 9433   { &key_mutex_mts_temp_tables_lock, 
"Relay_log_info::temp_tables_lock", 0},
 
 9434   { &key_mutex_slave_parallel_worker, 
"Worker_info::jobs_lock", 0},
 
 9435   { &key_structure_guard_mutex, 
"Query_cache::structure_guard_mutex", 0},
 
 9436   { &key_TABLE_SHARE_LOCK_ha_data, 
"TABLE_SHARE::LOCK_ha_data", 0},
 
 9437   { &key_LOCK_error_messages, 
"LOCK_error_messages", PSI_FLAG_GLOBAL},
 
 9438   { &key_LOG_INFO_lock, 
"LOG_INFO::lock", 0},
 
 9439   { &key_LOCK_thread_count, 
"LOCK_thread_count", PSI_FLAG_GLOBAL},
 
 9440   { &key_LOCK_log_throttle_qni, 
"LOCK_log_throttle_qni", PSI_FLAG_GLOBAL},
 
 9441   { &key_gtid_ensure_index_mutex, 
"Gtid_state", PSI_FLAG_GLOBAL},
 
 9442   { &key_LOCK_thread_created, 
"LOCK_thread_created", PSI_FLAG_GLOBAL }
 
 9445 PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger,
 
 9446   key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave,
 
 9447   key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock,
 
 9448   key_rwlock_global_sid_lock;
 
 9450 static PSI_rwlock_info all_server_rwlocks[]=
 
 9452 #if defined (HAVE_OPENSSL) && !defined(HAVE_YASSL) 
 9453   { &key_rwlock_openssl, 
"CRYPTO_dynlock_value::lock", 0},
 
 9455   { &key_rwlock_LOCK_grant, 
"LOCK_grant", PSI_FLAG_GLOBAL},
 
 9456   { &key_rwlock_LOCK_logger, 
"LOGGER::LOCK_logger", 0},
 
 9457   { &key_rwlock_LOCK_sys_init_connect, 
"LOCK_sys_init_connect", PSI_FLAG_GLOBAL},
 
 9458   { &key_rwlock_LOCK_sys_init_slave, 
"LOCK_sys_init_slave", PSI_FLAG_GLOBAL},
 
 9459   { &key_rwlock_LOCK_system_variables_hash, 
"LOCK_system_variables_hash", PSI_FLAG_GLOBAL},
 
 9460   { &key_rwlock_query_cache_query_lock, 
"Query_cache_query::lock", 0},
 
 9461   { &key_rwlock_global_sid_lock, 
"gtid_commit_rollback", PSI_FLAG_GLOBAL}
 
 9465 PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool;
 
 9468 PSI_cond_key key_BINLOG_update_cond,
 
 9469   key_COND_cache_status_changed, key_COND_manager,
 
 9470   key_COND_server_started,
 
 9471   key_delayed_insert_cond, key_delayed_insert_cond_client,
 
 9472   key_item_func_sleep_cond, key_master_info_data_cond,
 
 9473   key_master_info_start_cond, key_master_info_stop_cond,
 
 9474   key_master_info_sleep_cond,
 
 9475   key_relay_log_info_data_cond, key_relay_log_info_log_space_cond,
 
 9476   key_relay_log_info_start_cond, key_relay_log_info_stop_cond,
 
 9477   key_relay_log_info_sleep_cond, key_cond_slave_parallel_pend_jobs,
 
 9478   key_cond_slave_parallel_worker,
 
 9479   key_TABLE_SHARE_cond, key_user_level_lock_cond,
 
 9480   key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache;
 
 9481 PSI_cond_key key_RELAYLOG_update_cond;
 
 9482 PSI_cond_key key_BINLOG_COND_done;
 
 9483 PSI_cond_key key_RELAYLOG_COND_done;
 
 9484 PSI_cond_key key_BINLOG_prep_xids_cond;
 
 9485 PSI_cond_key key_RELAYLOG_prep_xids_cond;
 
 9486 PSI_cond_key key_gtid_ensure_index_cond;
 
 9488 static PSI_cond_info all_server_conds[]=
 
 9490 #if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) 
 9491   { &key_COND_handler_count, 
"COND_handler_count", PSI_FLAG_GLOBAL},
 
 9494   { &key_PAGE_cond, 
"PAGE::cond", 0},
 
 9495   { &key_COND_active, 
"TC_LOG_MMAP::COND_active", 0},
 
 9496   { &key_COND_pool, 
"TC_LOG_MMAP::COND_pool", 0},
 
 9498   { &key_BINLOG_COND_done, 
"MYSQL_BIN_LOG::COND_done", 0},
 
 9499   { &key_BINLOG_update_cond, 
"MYSQL_BIN_LOG::update_cond", 0},
 
 9500   { &key_BINLOG_prep_xids_cond, 
"MYSQL_BIN_LOG::prep_xids_cond", 0},
 
 9501   { &key_RELAYLOG_COND_done, 
"MYSQL_RELAY_LOG::COND_done", 0},
 
 9502   { &key_RELAYLOG_update_cond, 
"MYSQL_RELAY_LOG::update_cond", 0},
 
 9503   { &key_RELAYLOG_prep_xids_cond, 
"MYSQL_RELAY_LOG::prep_xids_cond", 0},
 
 9504   { &key_COND_cache_status_changed, 
"Query_cache::COND_cache_status_changed", 0},
 
 9505   { &key_COND_manager, 
"COND_manager", PSI_FLAG_GLOBAL},
 
 9506   { &key_COND_server_started, 
"COND_server_started", PSI_FLAG_GLOBAL},
 
 9507   { &key_delayed_insert_cond, 
"Delayed_insert::cond", 0},
 
 9508   { &key_delayed_insert_cond_client, 
"Delayed_insert::cond_client", 0},
 
 9509   { &key_item_func_sleep_cond, 
"Item_func_sleep::cond", 0},
 
 9510   { &key_master_info_data_cond, 
"Master_info::data_cond", 0},
 
 9511   { &key_master_info_start_cond, 
"Master_info::start_cond", 0},
 
 9512   { &key_master_info_stop_cond, 
"Master_info::stop_cond", 0},
 
 9513   { &key_master_info_sleep_cond, 
"Master_info::sleep_cond", 0},
 
 9514   { &key_relay_log_info_data_cond, 
"Relay_log_info::data_cond", 0},
 
 9515   { &key_relay_log_info_log_space_cond, 
"Relay_log_info::log_space_cond", 0},
 
 9516   { &key_relay_log_info_start_cond, 
"Relay_log_info::start_cond", 0},
 
 9517   { &key_relay_log_info_stop_cond, 
"Relay_log_info::stop_cond", 0},
 
 9518   { &key_relay_log_info_sleep_cond, 
"Relay_log_info::sleep_cond", 0},
 
 9519   { &key_cond_slave_parallel_pend_jobs, 
"Relay_log_info::pending_jobs_cond", 0},
 
 9520   { &key_cond_slave_parallel_worker, 
"Worker_info::jobs_cond", 0},
 
 9521   { &key_TABLE_SHARE_cond, 
"TABLE_SHARE::cond", 0},
 
 9522   { &key_user_level_lock_cond, 
"User_level_lock::cond", 0},
 
 9523   { &key_COND_thread_count, 
"COND_thread_count", PSI_FLAG_GLOBAL},
 
 9524   { &key_COND_thread_cache, 
"COND_thread_cache", PSI_FLAG_GLOBAL},
 
 9525   { &key_COND_flush_thread_cache, 
"COND_flush_thread_cache", PSI_FLAG_GLOBAL},
 
 9526   { &key_gtid_ensure_index_cond, 
"Gtid_state", PSI_FLAG_GLOBAL}
 
 9529 PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert,
 
 9530   key_thread_handle_manager, key_thread_main,
 
 9531   key_thread_one_connection, key_thread_signal_hand;
 
 9533 static PSI_thread_info all_server_threads[]=
 
 9535 #if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) 
 9536   { &key_thread_handle_con_namedpipes, 
"con_named_pipes", PSI_FLAG_GLOBAL},
 
 9539 #if defined(HAVE_SMEM) && !defined(EMBEDDED_LIBRARY) 
 9540   { &key_thread_handle_con_sharedmem, 
"con_shared_mem", PSI_FLAG_GLOBAL},
 
 9543 #if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) 
 9544   { &key_thread_handle_con_sockets, 
"con_sockets", PSI_FLAG_GLOBAL},
 
 9548   { &key_thread_handle_shutdown, 
"shutdown", PSI_FLAG_GLOBAL},
 
 9551   { &key_thread_bootstrap, 
"bootstrap", PSI_FLAG_GLOBAL},
 
 9552   { &key_thread_delayed_insert, 
"delayed_insert", 0},
 
 9553   { &key_thread_handle_manager, 
"manager", PSI_FLAG_GLOBAL},
 
 9554   { &key_thread_main, 
"main", PSI_FLAG_GLOBAL},
 
 9555   { &key_thread_one_connection, 
"one_connection", 0},
 
 9556   { &key_thread_signal_hand, 
"signal_handler", PSI_FLAG_GLOBAL}
 
 9560 PSI_file_key key_file_map;
 
 9563 PSI_file_key key_file_binlog, key_file_binlog_index, key_file_casetest,
 
 9564   key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file,
 
 9565   key_file_fileparser, key_file_frm, key_file_global_ddl_log, key_file_load,
 
 9566   key_file_loadfile, key_file_log_event_data, key_file_log_event_info,
 
 9567   key_file_master_info, key_file_misc, key_file_partition,
 
 9568   key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog,
 
 9569   key_file_trg, key_file_trn, key_file_init;
 
 9570 PSI_file_key key_file_query_log, key_file_slow_log;
 
 9571 PSI_file_key key_file_relaylog, key_file_relaylog_index;
 
 9573 static PSI_file_info all_server_files[]=
 
 9576   { &key_file_map, 
"map", 0},
 
 9578   { &key_file_binlog, 
"binlog", 0},
 
 9579   { &key_file_binlog_index, 
"binlog_index", 0},
 
 9580   { &key_file_relaylog, 
"relaylog", 0},
 
 9581   { &key_file_relaylog_index, 
"relaylog_index", 0},
 
 9582   { &key_file_casetest, 
"casetest", 0},
 
 9583   { &key_file_dbopt, 
"dbopt", 0},
 
 9584   { &key_file_des_key_file, 
"des_key_file", 0},
 
 9585   { &key_file_ERRMSG, 
"ERRMSG", 0},
 
 9586   { &key_select_to_file, 
"select_to_file", 0},
 
 9587   { &key_file_fileparser, 
"file_parser", 0},
 
 9588   { &key_file_frm, 
"FRM", 0},
 
 9589   { &key_file_global_ddl_log, 
"global_ddl_log", 0},
 
 9590   { &key_file_load, 
"load", 0},
 
 9591   { &key_file_loadfile, 
"LOAD_FILE", 0},
 
 9592   { &key_file_log_event_data, 
"log_event_data", 0},
 
 9593   { &key_file_log_event_info, 
"log_event_info", 0},
 
 9594   { &key_file_master_info, 
"master_info", 0},
 
 9595   { &key_file_misc, 
"misc", 0},
 
 9596   { &key_file_partition, 
"partition", 0},
 
 9597   { &key_file_pid, 
"pid", 0},
 
 9598   { &key_file_query_log, 
"query_log", 0},
 
 9599   { &key_file_relay_log_info, 
"relay_log_info", 0},
 
 9600   { &key_file_send_file, 
"send_file", 0},
 
 9601   { &key_file_slow_log, 
"slow_log", 0},
 
 9602   { &key_file_tclog, 
"tclog", 0},
 
 9603   { &key_file_trg, 
"trigger_name", 0},
 
 9604   { &key_file_trn, 
"trigger", 0},
 
 9605   { &key_file_init, 
"init", 0}
 
 9610 PSI_stage_info stage_allocating_local_table= { 0, 
"allocating local table", 0};
 
 9611 PSI_stage_info stage_alter_inplace_prepare= { 0, 
"preparing for alter table", 0};
 
 9613 PSI_stage_info stage_alter_inplace_commit= { 0, 
"committing alter table to storage engine", 0};
 
 9614 PSI_stage_info stage_changing_master= { 0, 
"Changing master", 0};
 
 9615 PSI_stage_info stage_checking_master_version= { 0, 
"Checking master version", 0};
 
 9616 PSI_stage_info stage_checking_permissions= { 0, 
"checking permissions", 0};
 
 9617 PSI_stage_info stage_checking_privileges_on_cached_query= { 0, 
"checking privileges on cached query", 0};
 
 9618 PSI_stage_info stage_checking_query_cache_for_query= { 0, 
"checking query cache for query", 0};
 
 9621 PSI_stage_info stage_connecting_to_master= { 0, 
"Connecting to master", 0};
 
 9622 PSI_stage_info stage_converting_heap_to_myisam= { 0, 
"converting HEAP to MyISAM", 0};
 
 9623 PSI_stage_info stage_copying_to_group_table= { 0, 
"Copying to group table", 0};
 
 9624 PSI_stage_info stage_copying_to_tmp_table= { 0, 
"Copying to tmp table", 0};
 
 9625 PSI_stage_info stage_copy_to_tmp_table= { 0, 
"copy to tmp table", 0};
 
 9626 PSI_stage_info stage_creating_delayed_handler= { 0, 
"Creating delayed handler", 0};
 
 9627 PSI_stage_info stage_creating_sort_index= { 0, 
"Creating sort index", 0};
 
 9629 PSI_stage_info stage_creating_tmp_table= { 0, 
"Creating tmp table", 0};
 
 9630 PSI_stage_info stage_deleting_from_main_table= { 0, 
"deleting from main table", 0};
 
 9631 PSI_stage_info stage_deleting_from_reference_tables= { 0, 
"deleting from reference tables", 0};
 
 9632 PSI_stage_info stage_discard_or_import_tablespace= { 0, 
"discard_or_import_tablespace", 0};
 
 9635 PSI_stage_info stage_execution_of_init_command= { 0, 
"Execution of init_command", 0};
 
 9637 PSI_stage_info stage_finished_reading_one_binlog_switching_to_next_binlog= { 0, 
"Finished reading one binlog; switching to next binlog", 0};
 
 9638 PSI_stage_info stage_flushing_relay_log_and_master_info_repository= { 0, 
"Flushing relay log and master info repository.", 0};
 
 9639 PSI_stage_info stage_flushing_relay_log_info_file= { 0, 
"Flushing relay-log info file.", 0};
 
 9641 PSI_stage_info stage_fulltext_initialization= { 0, 
"FULLTEXT initialization", 0};
 
 9642 PSI_stage_info stage_got_handler_lock= { 0, 
"got handler lock", 0};
 
 9646 PSI_stage_info stage_invalidating_query_cache_entries_table= { 0, 
"invalidating query cache entries (table)", 0};
 
 9647 PSI_stage_info stage_invalidating_query_cache_entries_table_list= { 0, 
"invalidating query cache entries (table list)", 0};
 
 9649 PSI_stage_info stage_logging_slow_query= { 0, 
"logging slow query", 0};
 
 9650 PSI_stage_info stage_making_temp_file_append_before_load_data= { 0, 
"Making temporary file (append) before replaying LOAD DATA INFILE.", 0};
 
 9651 PSI_stage_info stage_making_temp_file_create_before_load_data= { 0, 
"Making temporary file (create) before replaying LOAD DATA INFILE.", 0};
 
 9653 PSI_stage_info stage_master_has_sent_all_binlog_to_slave= { 0, 
"Master has sent all binlog to slave; waiting for binlog to be updated", 0};
 
 9657 PSI_stage_info stage_purging_old_relay_logs= { 0, 
"Purging old relay logs", 0};
 
 9659 PSI_stage_info stage_queueing_master_event_to_the_relay_log= { 0, 
"Queueing master event to the relay log", 0};
 
 9660 PSI_stage_info stage_reading_event_from_the_relay_log= { 0, 
"Reading event from the relay log", 0};
 
 9661 PSI_stage_info stage_registering_slave_on_master= { 0, 
"Registering slave on master", 0};
 
 9662 PSI_stage_info stage_removing_duplicates= { 0, 
"Removing duplicates", 0};
 
 9663 PSI_stage_info stage_removing_tmp_table= { 0, 
"removing tmp table", 0};
 
 9665 PSI_stage_info stage_rename_result_table= { 0, 
"rename result table", 0};
 
 9666 PSI_stage_info stage_requesting_binlog_dump= { 0, 
"Requesting binlog dump", 0};
 
 9668 PSI_stage_info stage_searching_rows_for_update= { 0, 
"Searching rows for update", 0};
 
 9669 PSI_stage_info stage_sending_binlog_event_to_slave= { 0, 
"Sending binlog event to slave", 0};
 
 9670 PSI_stage_info stage_sending_cached_result_to_client= { 0, 
"sending cached result to client", 0};
 
 9673 PSI_stage_info stage_slave_has_read_all_relay_log= { 0, 
"Slave has read all relay log; waiting for the slave I/O thread to update it", 0};
 
 9674 PSI_stage_info stage_sorting_for_group= { 0, 
"Sorting for group", 0};
 
 9675 PSI_stage_info stage_sorting_for_order= { 0, 
"Sorting for order", 0};
 
 9678 PSI_stage_info stage_sql_thd_waiting_until_delay= { 0, 
"Waiting until MASTER_DELAY seconds after master executed event", 0 };
 
 9679 PSI_stage_info stage_storing_result_in_query_cache= { 0, 
"storing result in query cache", 0};
 
 9680 PSI_stage_info stage_storing_row_into_queue= { 0, 
"storing row into queue", 0};
 
 9684 PSI_stage_info stage_updating_main_table= { 0, 
"updating main table", 0};
 
 9685 PSI_stage_info stage_updating_reference_tables= { 0, 
"updating reference tables", 0};
 
 9689 PSI_stage_info stage_verifying_table= { 0, 
"verifying table", 0};
 
 9690 PSI_stage_info stage_waiting_for_delay_list= { 0, 
"waiting for delay_list", 0};
 
 9691 PSI_stage_info stage_waiting_for_gtid_to_be_written_to_binary_log= { 0, 
"waiting for GTID to be written to binary log", 0};
 
 9692 PSI_stage_info stage_waiting_for_handler_insert= { 0, 
"waiting for handler insert", 0};
 
 9693 PSI_stage_info stage_waiting_for_handler_lock= { 0, 
"waiting for handler lock", 0};
 
 9694 PSI_stage_info stage_waiting_for_handler_open= { 0, 
"waiting for handler open", 0};
 
 9695 PSI_stage_info stage_waiting_for_insert= { 0, 
"Waiting for INSERT", 0};
 
 9696 PSI_stage_info stage_waiting_for_master_to_send_event= { 0, 
"Waiting for master to send event", 0};
 
 9697 PSI_stage_info stage_waiting_for_master_update= { 0, 
"Waiting for master update", 0};
 
 9698 PSI_stage_info stage_waiting_for_relay_log_space= { 0, 
"Waiting for the slave SQL thread to free enough relay log space", 0};
 
 9699 PSI_stage_info stage_waiting_for_slave_mutex_on_exit= { 0, 
"Waiting for slave mutex on exit", 0};
 
 9700 PSI_stage_info stage_waiting_for_slave_thread_to_start= { 0, 
"Waiting for slave thread to start", 0};
 
 9701 PSI_stage_info stage_waiting_for_table_flush= { 0, 
"Waiting for table flush", 0};
 
 9702 PSI_stage_info stage_waiting_for_query_cache_lock= { 0, 
"Waiting for query cache lock", 0};
 
 9703 PSI_stage_info stage_waiting_for_the_next_event_in_relay_log= { 0, 
"Waiting for the next event in relay log", 0};
 
 9704 PSI_stage_info stage_waiting_for_the_slave_thread_to_advance_position= { 0, 
"Waiting for the slave SQL thread to advance position", 0};
 
 9705 PSI_stage_info stage_waiting_to_finalize_termination= { 0, 
"Waiting to finalize termination", 0};
 
 9706 PSI_stage_info stage_waiting_to_get_readlock= { 0, 
"Waiting to get readlock", 0};
 
 9707 PSI_stage_info stage_slave_waiting_workers_to_exit= { 0, 
"Waiting for workers to exit", 0};
 
 9708 PSI_stage_info stage_slave_waiting_worker_to_release_partition= { 0, 
"Waiting for Slave Worker to release partition", 0};
 
 9709 PSI_stage_info stage_slave_waiting_worker_to_free_events= { 0, 
"Waiting for Slave Workers to free pending events", 0};
 
 9710 PSI_stage_info stage_slave_waiting_worker_queue= { 0, 
"Waiting for Slave Worker queue", 0};
 
 9711 PSI_stage_info stage_slave_waiting_event_from_coordinator= { 0, 
"Waiting for an event from Coordinator", 0};
 
 9713 #ifdef HAVE_PSI_INTERFACE 
 9717   & stage_after_create,
 
 9718   & stage_allocating_local_table,
 
 9719   & stage_alter_inplace_prepare,
 
 9720   & stage_alter_inplace,
 
 9721   & stage_alter_inplace_commit,
 
 9722   & stage_changing_master,
 
 9723   & stage_checking_master_version,
 
 9724   & stage_checking_permissions,
 
 9725   & stage_checking_privileges_on_cached_query,
 
 9726   & stage_checking_query_cache_for_query,
 
 9727   & stage_cleaning_up,
 
 9728   & stage_closing_tables,
 
 9729   & stage_connecting_to_master,
 
 9730   & stage_converting_heap_to_myisam,
 
 9731   & stage_copying_to_group_table,
 
 9732   & stage_copying_to_tmp_table,
 
 9733   & stage_copy_to_tmp_table,
 
 9734   & stage_creating_delayed_handler,
 
 9735   & stage_creating_sort_index,
 
 9736   & stage_creating_table,
 
 9737   & stage_creating_tmp_table,
 
 9738   & stage_deleting_from_main_table,
 
 9739   & stage_deleting_from_reference_tables,
 
 9740   & stage_discard_or_import_tablespace,
 
 9743   & stage_execution_of_init_command,
 
 9745   & stage_finished_reading_one_binlog_switching_to_next_binlog,
 
 9746   & stage_flushing_relay_log_and_master_info_repository,
 
 9747   & stage_flushing_relay_log_info_file,
 
 9748   & stage_freeing_items,
 
 9749   & stage_fulltext_initialization,
 
 9750   & stage_got_handler_lock,
 
 9751   & stage_got_old_table,
 
 9754   & stage_invalidating_query_cache_entries_table,
 
 9755   & stage_invalidating_query_cache_entries_table_list,
 
 9756   & stage_killing_slave,
 
 9757   & stage_logging_slow_query,
 
 9758   & stage_making_temp_file_append_before_load_data,
 
 9759   & stage_making_temp_file_create_before_load_data,
 
 9760   & stage_manage_keys,
 
 9761   & stage_master_has_sent_all_binlog_to_slave,
 
 9762   & stage_opening_tables,
 
 9765   & stage_purging_old_relay_logs,
 
 9767   & stage_queueing_master_event_to_the_relay_log,
 
 9768   & stage_reading_event_from_the_relay_log,
 
 9769   & stage_registering_slave_on_master,
 
 9770   & stage_removing_duplicates,
 
 9771   & stage_removing_tmp_table,
 
 9773   & stage_rename_result_table,
 
 9774   & stage_requesting_binlog_dump,
 
 9776   & stage_searching_rows_for_update,
 
 9777   & stage_sending_binlog_event_to_slave,
 
 9778   & stage_sending_cached_result_to_client,
 
 9779   & stage_sending_data,
 
 9781   & stage_slave_has_read_all_relay_log,
 
 9782   & stage_sorting_for_group,
 
 9783   & stage_sorting_for_order,
 
 9784   & stage_sorting_result,
 
 9785   & stage_sql_thd_waiting_until_delay,
 
 9787   & stage_storing_result_in_query_cache,
 
 9788   & stage_storing_row_into_queue,
 
 9789   & stage_system_lock,
 
 9792   & stage_updating_main_table,
 
 9793   & stage_updating_reference_tables,
 
 9794   & stage_upgrading_lock,
 
 9797   & stage_verifying_table,
 
 9798   & stage_waiting_for_delay_list,
 
 9799   & stage_waiting_for_handler_insert,
 
 9800   & stage_waiting_for_handler_lock,
 
 9801   & stage_waiting_for_handler_open,
 
 9802   & stage_waiting_for_insert,
 
 9803   & stage_waiting_for_master_to_send_event,
 
 9804   & stage_waiting_for_master_update,
 
 9805   & stage_waiting_for_slave_mutex_on_exit,
 
 9806   & stage_waiting_for_slave_thread_to_start,
 
 9807   & stage_waiting_for_table_flush,
 
 9808   & stage_waiting_for_query_cache_lock,
 
 9809   & stage_waiting_for_the_next_event_in_relay_log,
 
 9810   & stage_waiting_for_the_slave_thread_to_advance_position,
 
 9811   & stage_waiting_to_finalize_termination,
 
 9812   & stage_waiting_to_get_readlock
 
 9815 PSI_socket_key key_socket_tcpip, key_socket_unix, key_socket_client_connection;
 
 9817 static PSI_socket_info all_server_sockets[]=
 
 9819   { &key_socket_tcpip, 
"server_tcpip_socket", PSI_FLAG_GLOBAL},
 
 9820   { &key_socket_unix, 
"server_unix_socket", PSI_FLAG_GLOBAL},
 
 9821   { &key_socket_client_connection, 
"client_connection", 0}
 
 9828 void init_server_psi_keys(
void)
 
 9830   const char* category= 
"sql";
 
 9833   count= array_elements(all_server_mutexes);
 
 9836   count= array_elements(all_server_rwlocks);
 
 9839   count= array_elements(all_server_conds);
 
 9842   count= array_elements(all_server_threads);
 
 9845   count= array_elements(all_server_files);
 
 9848   count= array_elements(all_server_stages);
 
 9851   count= array_elements(all_server_sockets);
 
 9854 #ifdef HAVE_PSI_STATEMENT_INTERFACE 
 9855   init_sql_statement_info();
 
 9856   count= array_elements(sql_statement_info);
 
 9860   init_com_statement_info();
 
 9861   count= array_elements(com_statement_info);
 
 9874   stmt_info_new_packet.m_key= 0;
 
 9875   stmt_info_new_packet.m_name= 
"";
 
 9876   stmt_info_new_packet.m_flags= PSI_FLAG_MUTABLE;
 
 9885   stmt_info_rpl.m_key= 0;
 
 9886   stmt_info_rpl.m_name= 
"relay_log";
 
 9887   stmt_info_rpl.m_flags= PSI_FLAG_MUTABLE;