208
207
{&Arg_comparator::compare_row, &Arg_comparator::compare_e_row},
209
208
{&Arg_comparator::compare_decimal, &Arg_comparator::compare_e_decimal}};
211
const char *log_output_names[] = { "NONE", "FILE", "TABLE", NullS};
212
static const unsigned int log_output_names_len[]= { 4, 4, 5, 0 };
210
const char *log_output_names[] = { "NONE", "FILE", NullS};
211
static const unsigned int log_output_names_len[]= { 4, 4, 0 };
213
212
TYPELIB log_output_typelib= {array_elements(log_output_names)-1,"",
214
213
log_output_names,
215
214
(unsigned int *) log_output_names_len};
1087
1090
static void network_init(void)
1092
1094
uint this_wait;
1094
1096
char port_buf[NI_MAXSERV];
1097
struct addrinfo *ai;
1098
struct addrinfo *next;
1099
struct addrinfo hints;
1096
1102
if (thread_scheduler.init())
1097
1103
unireg_abort(1); /* purecov: inspected */
1101
if (mysqld_port != 0 && !opt_disable_networking && !opt_bootstrap)
1103
struct addrinfo *ai;
1104
struct addrinfo hints;
1107
bzero(&hints, sizeof (hints));
1108
hints.ai_flags= AI_PASSIVE;
1109
hints.ai_socktype= SOCK_STREAM;
1110
hints.ai_family= AF_UNSPEC;
1112
snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
1113
error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
1116
sql_perror(ER(ER_IPSOCK_ERROR)); /* purecov: tested */
1117
unireg_abort(1); /* purecov: tested */
1121
ip_sock= socket(ai->ai_family, ai->ai_socktype,
1107
memset(fds, 0, sizeof(struct pollfd) * UINT8_MAX);
1108
memset(&hints, 0, sizeof (hints));
1109
hints.ai_flags= AI_PASSIVE;
1110
hints.ai_socktype= SOCK_STREAM;
1111
hints.ai_family= AF_INET;
1112
hints.ai_protocol= IPPROTO_TCP;
1114
snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
1115
error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
1118
sql_perror(ER(ER_IPSOCK_ERROR)); /* purecov: tested */
1119
unireg_abort(1); /* purecov: tested */
1122
for (next= ai, pollfd_count= 0; next; next= next->ai_next, pollfd_count++)
1126
ip_sock= socket(next->ai_family, next->ai_socktype, next->ai_protocol);
1124
1128
if (ip_sock == INVALID_SOCKET)
1127
1131
unireg_abort(1); /* purecov: tested */
1131
We should not use SO_REUSEADDR on windows as this would enable a
1132
user to open two mysqld servers with the same TCP/IP port.
1135
(void) setsockopt(ip_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,sizeof(arg));
1134
fds[pollfd_count].fd= ip_sock;
1135
fds[pollfd_count].events= POLLIN | POLLERR;
1139
For interoperability with older clients, IPv6 socket should
1140
listen on both IPv6 and IPv4 wildcard addresses.
1141
Turn off IPV6_V6ONLY option.
1143
if (ai->ai_family == AF_INET6)
1137
/* Add options for our listening socket */
1146
(void) setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
1139
struct linger ling = {0, 0};
1142
(void) setsockopt(ip_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&flags, sizeof(flags));
1143
(void) setsockopt(ip_sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags));
1144
(void) setsockopt(ip_sock, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling));
1145
(void) setsockopt(ip_sock, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags));
1151
1150
Sometimes the port is not released fast enough when stopping and
1152
1151
restarting the server. This happens quite often with the test suite
1745
1744
REFRESH_THREADS | REFRESH_HOSTS),
1746
1745
(TABLE_LIST*) 0, ¬_used); // Flush logs
1748
/* reenable logs after the options were reloaded */
1749
if (log_output_options & LOG_NONE)
1751
logger.set_handlers(LOG_FILE,
1752
opt_slow_log ? LOG_TABLE : LOG_NONE,
1753
opt_log ? LOG_TABLE : LOG_NONE);
1757
logger.set_handlers(LOG_FILE,
1758
opt_slow_log ? log_output_options : LOG_NONE,
1759
opt_log ? log_output_options : LOG_NONE);
1747
logger.set_handlers(LOG_FILE,
1748
opt_slow_log ? log_output_options : LOG_NONE,
1749
opt_log ? log_output_options : LOG_NONE);
1762
1751
#ifdef USE_ONE_SIGNAL_HAND
1763
1752
case THR_SERVER_ALARM:
2226
2215
if (my_database_names_init())
2230
Ensure that lower_case_table_names is set on system where we have case
2231
insensitive names. If this is not done the users MyISAM tables will
2232
get corrupted if accesses with names of different case.
2234
lower_case_file_system= test_if_case_insensitive(mysql_real_data_home);
2235
if (!lower_case_table_names && lower_case_file_system == 1)
2237
if (lower_case_table_names_used)
2239
if (global_system_variables.log_warnings)
2240
sql_print_warning("\
2241
You have forced lower_case_table_names to 0 through a command-line \
2242
option, even though your file system '%s' is case insensitive. This means \
2243
that you can corrupt a MyISAM table by accessing it with different cases. \
2244
You should consider changing lower_case_table_names to 1 or 2",
2245
mysql_real_data_home);
2249
if (global_system_variables.log_warnings)
2250
sql_print_warning("Setting lower_case_table_names=2 because file system for %s is case insensitive", mysql_real_data_home);
2251
lower_case_table_names= 2;
2254
else if (lower_case_table_names == 2 &&
2255
!(lower_case_file_system=
2256
(test_if_case_insensitive(mysql_real_data_home) == 1)))
2258
if (global_system_variables.log_warnings)
2259
sql_print_warning("lower_case_table_names was set to 2, even though your "
2260
"the file system '%s' is case sensitive. Now setting "
2261
"lower_case_table_names to 0 to avoid future problems.",
2262
mysql_real_data_home);
2263
lower_case_table_names= 0;
2267
lower_case_file_system=
2268
(test_if_case_insensitive(mysql_real_data_home) == 1);
2271
2219
/* Reset table_alias_charset, now that lower_case_table_names is set. */
2272
table_alias_charset= (lower_case_table_names ?
2273
files_charset_info :
2220
lower_case_table_names= 1; /* This we need to look at */
2221
table_alias_charset= files_charset_info;
2701
2645
error_handler_hook= my_message_sql;
2702
2646
start_signal_handler(); // Creates pidfile
2704
if (mysql_rm_tmp_tables() || my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
2648
if (mysql_rm_tmp_tables() || my_tz_init((THD *)0, default_tz_name, false))
2707
2651
select_thread_in_use=0;
2708
2652
(void) pthread_kill(signal_thread, MYSQL_KILL_SIGNAL);
2711
(void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore
2654
(void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore
2716
2659
init_status_vars();
2717
if (opt_bootstrap) /* If running with bootstrap, do not start replication. */
2718
opt_skip_slave_start= 1;
2720
2661
init_slave() must be called after the thread keys are created.
2721
2662
Some parts of the code (e.g. SHOW STATUS LIKE 'slave_running' and other
2837
2778
void handle_connections_sockets()
2839
2781
my_socket sock,new_sock;
2840
2782
uint error_count=0;
2841
uint max_used_connection= (uint)ip_sock+1;
2842
fd_set readFDs,clientFDs;
2844
2784
struct sockaddr_storage cAddr;
2845
int ip_flags=0, flags;
2846
2785
st_vio *vio_tmp;
2848
FD_ZERO(&clientFDs);
2849
if (ip_sock != INVALID_SOCKET)
2851
FD_SET(ip_sock,&clientFDs);
2852
ip_flags = fcntl(ip_sock, F_GETFL, 0);
2854
2787
MAYBE_BROKEN_SYSCALL;
2855
2788
while (!abort_loop)
2858
if (select((int) max_used_connection,&readFDs,0,0,0) < 0)
2792
if ((number_of= poll(fds, pollfd_count, -1)) == -1)
2860
2794
if (socket_errno != SOCKET_EINTR)
2865
2799
MAYBE_BROKEN_SYSCALL
2805
#ifdef FIXME_IF_WE_WERE_KEEPING_THIS
2806
assert(number_of > 1); /* Not handling this at the moment */
2868
2809
if (abort_loop)
2870
2811
MAYBE_BROKEN_SYSCALL;
2874
/* Is this a new connection request ? */
2815
for (x= 0, sock= -1; x < pollfd_count; x++)
2817
if (fds[x].revents == POLLIN)
2880
#if !defined(NO_FCNTL_NONBLOCK)
2881
if (!(test_flags & TEST_BLOCKING))
2883
#if defined(O_NONBLOCK)
2884
fcntl(sock, F_SETFL, flags | O_NONBLOCK);
2885
#elif defined(O_NDELAY)
2886
fcntl(sock, F_SETFL, flags | O_NDELAY);
2889
#endif /* NO_FCNTL_NONBLOCK */
2890
2825
for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++)
2892
2827
size_socket length= sizeof(struct sockaddr_storage);
2893
2828
new_sock= accept(sock, (struct sockaddr *)(&cAddr),
2895
if (new_sock != INVALID_SOCKET ||
2896
(socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
2830
if (new_sock != INVALID_SOCKET || (socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
2898
MAYBE_BROKEN_SYSCALL;
2899
#if !defined(NO_FCNTL_NONBLOCK)
2900
if (!(test_flags & TEST_BLOCKING))
2902
if (retry == MAX_ACCEPT_RETRY - 1)
2903
fcntl(sock, F_SETFL, flags); // Try without O_NONBLOCK
2907
#if !defined(NO_FCNTL_NONBLOCK)
2908
if (!(test_flags & TEST_BLOCKING))
2909
fcntl(sock, F_SETFL, flags);
2911
2835
if (new_sock == INVALID_SOCKET)
2913
2837
if ((error_count++ & 255) == 0) // This can happen often
3650
3574
"The argument will be treated as a decimal value with microsecond precission.",
3651
3575
(char**) &long_query_time, (char**) &long_query_time, 0, GET_DOUBLE,
3652
3576
REQUIRED_ARG, 10, 0, LONG_TIMEOUT, 0, 0, 0},
3653
{"lower_case_table_names", OPT_LOWER_CASE_TABLE_NAMES,
3654
"If set to 1 table names are stored in lowercase on disk and table names will be case-insensitive. Should be set to 2 if you are using a case insensitive file system",
3655
(char**) &lower_case_table_names,
3656
(char**) &lower_case_table_names, 0, GET_UINT, OPT_ARG,
3657
#ifdef FN_NO_CASE_SENCE
3663
3577
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
3664
3578
"Max packetlength to send/receive from to server.",
3665
3579
(char**) &global_system_variables.max_allowed_packet,
4461
4374
opt_error_log= 1;
4463
4376
case (int)OPT_REPLICATE_IGNORE_DB:
4465
rpl_filter->add_ignore_db(argument);
4378
rpl_filter->add_ignore_db(argument);
4468
4381
case (int)OPT_REPLICATE_DO_DB:
4470
rpl_filter->add_do_db(argument);
4383
rpl_filter->add_do_db(argument);
4473
4386
case (int)OPT_REPLICATE_REWRITE_DB:
4475
char* key = argument,*p, *val;
4477
if (!(p= strstr(argument, "->")))
4480
"Bad syntax in replicate-rewrite-db - missing '->'!\n");
4484
while (my_isspace(mysqld_charset, *p) && p > argument)
4489
"Bad syntax in replicate-rewrite-db - empty FROM db!\n");
4494
while (*val && my_isspace(mysqld_charset, *val))
4499
"Bad syntax in replicate-rewrite-db - empty TO db!\n");
4503
rpl_filter->add_db_rewrite(key, val);
4388
char* key = argument,*p, *val;
4390
if (!(p= strstr(argument, "->")))
4393
"Bad syntax in replicate-rewrite-db - missing '->'!\n");
4397
while (my_isspace(mysqld_charset, *p) && p > argument)
4402
"Bad syntax in replicate-rewrite-db - empty FROM db!\n");
4407
while (*val && my_isspace(mysqld_charset, *val))
4412
"Bad syntax in replicate-rewrite-db - empty TO db!\n");
4416
rpl_filter->add_db_rewrite(key, val);
4507
4420
case (int)OPT_BINLOG_IGNORE_DB:
4509
binlog_filter->add_ignore_db(argument);
4422
binlog_filter->add_ignore_db(argument);
4512
4425
case OPT_BINLOG_FORMAT:
4515
id= find_type_or_exit(argument, &binlog_format_typelib, opt->name);
4516
global_system_variables.binlog_format= opt_binlog_format_id= id - 1;
4428
id= find_type_or_exit(argument, &binlog_format_typelib, opt->name);
4429
global_system_variables.binlog_format= opt_binlog_format_id= id - 1;
4519
4432
case (int)OPT_BINLOG_DO_DB:
4521
binlog_filter->add_do_db(argument);
4434
binlog_filter->add_do_db(argument);
4524
4437
case (int)OPT_REPLICATE_DO_TABLE:
4526
if (rpl_filter->add_do_table(argument))
4528
fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
4439
if (rpl_filter->add_do_table(argument))
4441
fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
4533
4446
case (int)OPT_REPLICATE_WILD_DO_TABLE:
4535
if (rpl_filter->add_wild_do_table(argument))
4537
fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
4448
if (rpl_filter->add_wild_do_table(argument))
4450
fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
4542
4455
case (int)OPT_REPLICATE_WILD_IGNORE_TABLE:
4544
if (rpl_filter->add_wild_ignore_table(argument))
4546
fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
4457
if (rpl_filter->add_wild_ignore_table(argument))
4459
fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
4551
4464
case (int)OPT_REPLICATE_IGNORE_TABLE:
4553
if (rpl_filter->add_ignore_table(argument))
4555
fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
4466
if (rpl_filter->add_ignore_table(argument))
4468
fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
4560
4473
case (int) OPT_SLOW_QUERY_LOG:
4561
4474
opt_slow_log= 1;
4563
4476
#ifdef WITH_CSV_STORAGE_ENGINE
4564
4477
case OPT_LOG_OUTPUT:
4566
if (!argument || !argument[0])
4568
log_output_options= LOG_FILE;
4569
log_output_str= log_output_typelib.type_names[1];
4479
if (!argument || !argument[0])
4481
log_output_options= LOG_FILE;
4482
log_output_str= log_output_typelib.type_names[1];
4486
log_output_str= argument;
4488
find_bit_type_or_exit(argument, &log_output_typelib, opt->name);
4573
log_output_str= argument;
4575
find_bit_type_or_exit(argument, &log_output_typelib, opt->name);
4580
4493
case (int) OPT_SKIP_NEW:
4581
4494
opt_specialflag|= SPECIAL_NO_NEW_FUNC;
4667
4577
charsets_dir = mysql_charsets_dir;
4669
4579
case OPT_TX_ISOLATION:
4672
type= find_type_or_exit(argument, &tx_isolation_typelib, opt->name);
4673
global_system_variables.tx_isolation= (type-1);
4582
type= find_type_or_exit(argument, &tx_isolation_typelib, opt->name);
4583
global_system_variables.tx_isolation= (type-1);
4676
4586
case OPT_MYISAM_RECOVER:
4680
myisam_recover_options= HA_RECOVER_DEFAULT;
4681
myisam_recover_options_str= myisam_recover_typelib.type_names[0];
4683
else if (!argument[0])
4685
myisam_recover_options= HA_RECOVER_NONE;
4686
myisam_recover_options_str= "OFF";
4690
myisam_recover_options_str=argument;
4691
myisam_recover_options=
4692
find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name);
4694
ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
4590
myisam_recover_options= HA_RECOVER_DEFAULT;
4591
myisam_recover_options_str= myisam_recover_typelib.type_names[0];
4593
else if (!argument[0])
4595
myisam_recover_options= HA_RECOVER_NONE;
4596
myisam_recover_options_str= "OFF";
4600
myisam_recover_options_str=argument;
4601
myisam_recover_options=
4602
find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name);
4604
ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
4697
4607
case OPT_TC_HEURISTIC_RECOVER:
4698
4608
tc_heuristic_recover= find_type_or_exit(argument,
4699
4609
&tc_heuristic_recover_typelib,
4702
4612
case OPT_MYISAM_STATS_METHOD:
4707
myisam_stats_method_str= argument;
4708
method= find_type_or_exit(argument, &myisam_stats_method_typelib,
4712
method_conv= MI_STATS_METHOD_IGNORE_NULLS;
4715
method_conv= MI_STATS_METHOD_NULLS_EQUAL;
4719
method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
4617
myisam_stats_method_str= argument;
4618
method= find_type_or_exit(argument, &myisam_stats_method_typelib,
4622
method_conv= MI_STATS_METHOD_IGNORE_NULLS;
4625
method_conv= MI_STATS_METHOD_NULLS_EQUAL;
4629
method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
4632
global_system_variables.myisam_stats_method= method_conv;
4722
global_system_variables.myisam_stats_method= method_conv;
4725
case OPT_LOWER_CASE_TABLE_NAMES:
4726
lower_case_table_names= argument ? atoi(argument) : 1;
4727
lower_case_table_names_used= 1;
5067
Check if file system used for databases is case insensitive.
5069
@param dir_name Directory to test
5072
-1 Don't know (Test failed)
5074
0 File system is case sensitive
5076
1 File system is case insensitive
5079
static int test_if_case_insensitive(const char *dir_name)
5083
char buff[FN_REFLEN], buff2[FN_REFLEN];
5084
struct stat stat_info;
5086
fn_format(buff, glob_hostname, dir_name, ".lower-test",
5087
MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
5088
fn_format(buff2, glob_hostname, dir_name, ".LOWER-TEST",
5089
MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
5090
(void) my_delete(buff2, MYF(0));
5091
if ((file= my_create(buff, 0666, O_RDWR, MYF(0))) < 0)
5093
sql_print_warning("Can't create test file %s", buff);
5096
my_close(file, MYF(0));
5097
if (!stat(buff2, &stat_info))
5098
result= 1; // Can access file
5099
(void) my_delete(buff, MYF(MY_WME));
5105
4972
Create file to store pid number.
5107
4974
static void create_pid_file()