1088
1092
static void network_init(void)
1093
1096
uint this_wait;
1095
1098
char port_buf[NI_MAXSERV];
1099
struct addrinfo *ai;
1100
struct addrinfo *next;
1101
struct addrinfo hints;
1097
1104
if (thread_scheduler.init())
1098
1105
unireg_abort(1); /* purecov: inspected */
1102
if (mysqld_port != 0 && !opt_disable_networking && !opt_bootstrap)
1104
struct addrinfo *ai;
1105
struct addrinfo hints;
1108
bzero(&hints, sizeof (hints));
1109
hints.ai_flags= AI_PASSIVE;
1110
hints.ai_socktype= SOCK_STREAM;
1111
hints.ai_family= AF_UNSPEC;
1113
snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
1114
error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
1117
sql_perror(ER(ER_IPSOCK_ERROR)); /* purecov: tested */
1118
unireg_abort(1); /* purecov: tested */
1122
ip_sock= socket(ai->ai_family, ai->ai_socktype,
1109
memset(fds, 0, sizeof(struct pollfd) * UINT8_MAX);
1110
memset(&hints, 0, sizeof (hints));
1111
hints.ai_flags= AI_PASSIVE;
1112
hints.ai_socktype= SOCK_STREAM;
1113
hints.ai_family= AF_INET;
1114
hints.ai_protocol= IPPROTO_TCP;
1116
snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
1117
error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
1120
sql_perror(ER(ER_IPSOCK_ERROR)); /* purecov: tested */
1121
unireg_abort(1); /* purecov: tested */
1124
for (next= ai, pollfd_count= 0; next; next= next->ai_next, pollfd_count++)
1128
ip_sock= socket(next->ai_family, next->ai_socktype, next->ai_protocol);
1125
1130
if (ip_sock == INVALID_SOCKET)
1128
1133
unireg_abort(1); /* purecov: tested */
1132
We should not use SO_REUSEADDR on windows as this would enable a
1133
user to open two mysqld servers with the same TCP/IP port.
1136
(void) setsockopt(ip_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,sizeof(arg));
1136
fds[pollfd_count].fd= ip_sock;
1137
fds[pollfd_count].events= POLLIN | POLLERR;
1140
For interoperability with older clients, IPv6 socket should
1141
listen on both IPv6 and IPv4 wildcard addresses.
1142
Turn off IPV6_V6ONLY option.
1144
if (ai->ai_family == AF_INET6)
1139
/* Add options for our listening socket */
1147
(void) setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
1141
struct linger ling = {0, 0};
1144
(void) setsockopt(ip_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&flags, sizeof(flags));
1145
(void) setsockopt(ip_sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags));
1146
(void) setsockopt(ip_sock, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling));
1147
(void) setsockopt(ip_sock, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags));
1152
1152
Sometimes the port is not released fast enough when stopping and
1153
1153
restarting the server. This happens quite often with the test suite
2218
2217
if (my_database_names_init())
2222
Ensure that lower_case_table_names is set on system where we have case
2223
insensitive names. If this is not done the users MyISAM tables will
2224
get corrupted if accesses with names of different case.
2226
lower_case_file_system= test_if_case_insensitive(mysql_real_data_home);
2227
if (!lower_case_table_names && lower_case_file_system == 1)
2229
if (lower_case_table_names_used)
2231
if (global_system_variables.log_warnings)
2232
sql_print_warning("\
2233
You have forced lower_case_table_names to 0 through a command-line \
2234
option, even though your file system '%s' is case insensitive. This means \
2235
that you can corrupt a MyISAM table by accessing it with different cases. \
2236
You should consider changing lower_case_table_names to 1 or 2",
2237
mysql_real_data_home);
2241
if (global_system_variables.log_warnings)
2242
sql_print_warning("Setting lower_case_table_names=2 because file system for %s is case insensitive", mysql_real_data_home);
2243
lower_case_table_names= 2;
2246
else if (lower_case_table_names == 2 &&
2247
!(lower_case_file_system=
2248
(test_if_case_insensitive(mysql_real_data_home) == 1)))
2250
if (global_system_variables.log_warnings)
2251
sql_print_warning("lower_case_table_names was set to 2, even though your "
2252
"the file system '%s' is case sensitive. Now setting "
2253
"lower_case_table_names to 0 to avoid future problems.",
2254
mysql_real_data_home);
2255
lower_case_table_names= 0;
2259
lower_case_file_system=
2260
(test_if_case_insensitive(mysql_real_data_home) == 1);
2263
2221
/* Reset table_alias_charset, now that lower_case_table_names is set. */
2264
table_alias_charset= (lower_case_table_names ?
2265
files_charset_info :
2222
lower_case_table_names= 1; /* This we need to look at */
2223
table_alias_charset= files_charset_info;
2693
2647
error_handler_hook= my_message_sql;
2694
2648
start_signal_handler(); // Creates pidfile
2696
if (mysql_rm_tmp_tables() || my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
2650
if (mysql_rm_tmp_tables() || my_tz_init((THD *)0, default_tz_name, false))
2699
2653
select_thread_in_use=0;
2700
2654
(void) pthread_kill(signal_thread, MYSQL_KILL_SIGNAL);
2703
(void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore
2656
(void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore
2708
2661
init_status_vars();
2709
if (opt_bootstrap) /* If running with bootstrap, do not start replication. */
2710
opt_skip_slave_start= 1;
2712
2663
init_slave() must be called after the thread keys are created.
2713
2664
Some parts of the code (e.g. SHOW STATUS LIKE 'slave_running' and other
2829
2780
void handle_connections_sockets()
2831
2783
my_socket sock,new_sock;
2832
2784
uint error_count=0;
2833
uint max_used_connection= (uint)ip_sock+1;
2834
fd_set readFDs,clientFDs;
2836
2786
struct sockaddr_storage cAddr;
2837
int ip_flags=0, flags;
2838
2787
st_vio *vio_tmp;
2840
FD_ZERO(&clientFDs);
2841
if (ip_sock != INVALID_SOCKET)
2843
FD_SET(ip_sock,&clientFDs);
2844
ip_flags = fcntl(ip_sock, F_GETFL, 0);
2846
2789
MAYBE_BROKEN_SYSCALL;
2847
2790
while (!abort_loop)
2850
if (select((int) max_used_connection,&readFDs,0,0,0) < 0)
2794
if ((number_of= poll(fds, pollfd_count, -1)) == -1)
2852
2796
if (socket_errno != SOCKET_EINTR)
2857
2801
MAYBE_BROKEN_SYSCALL
2807
#ifdef FIXME_IF_WE_WERE_KEEPING_THIS
2808
assert(number_of > 1); /* Not handling this at the moment */
2860
2811
if (abort_loop)
2862
2813
MAYBE_BROKEN_SYSCALL;
2866
/* Is this a new connection request ? */
2817
for (x= 0, sock= -1; x < pollfd_count; x++)
2819
if (fds[x].revents == POLLIN)
2872
#if !defined(NO_FCNTL_NONBLOCK)
2873
if (!(test_flags & TEST_BLOCKING))
2875
#if defined(O_NONBLOCK)
2876
fcntl(sock, F_SETFL, flags | O_NONBLOCK);
2877
#elif defined(O_NDELAY)
2878
fcntl(sock, F_SETFL, flags | O_NDELAY);
2881
#endif /* NO_FCNTL_NONBLOCK */
2882
2827
for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++)
2884
2829
size_socket length= sizeof(struct sockaddr_storage);
2885
2830
new_sock= accept(sock, (struct sockaddr *)(&cAddr),
2887
if (new_sock != INVALID_SOCKET ||
2888
(socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
2832
if (new_sock != INVALID_SOCKET || (socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
2890
MAYBE_BROKEN_SYSCALL;
2891
#if !defined(NO_FCNTL_NONBLOCK)
2892
if (!(test_flags & TEST_BLOCKING))
2894
if (retry == MAX_ACCEPT_RETRY - 1)
2895
fcntl(sock, F_SETFL, flags); // Try without O_NONBLOCK
2899
#if !defined(NO_FCNTL_NONBLOCK)
2900
if (!(test_flags & TEST_BLOCKING))
2901
fcntl(sock, F_SETFL, flags);
2903
2837
if (new_sock == INVALID_SOCKET)
2905
2839
if ((error_count++ & 255) == 0) // This can happen often
3642
3576
"The argument will be treated as a decimal value with microsecond precission.",
3643
3577
(char**) &long_query_time, (char**) &long_query_time, 0, GET_DOUBLE,
3644
3578
REQUIRED_ARG, 10, 0, LONG_TIMEOUT, 0, 0, 0},
3645
{"lower_case_table_names", OPT_LOWER_CASE_TABLE_NAMES,
3646
"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",
3647
(char**) &lower_case_table_names,
3648
(char**) &lower_case_table_names, 0, GET_UINT, OPT_ARG,
3649
#ifdef FN_NO_CASE_SENCE
3655
3579
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
3656
3580
"Max packetlength to send/receive from to server.",
3657
3581
(char**) &global_system_variables.max_allowed_packet,
4453
4376
opt_error_log= 1;
4455
4378
case (int)OPT_REPLICATE_IGNORE_DB:
4457
rpl_filter->add_ignore_db(argument);
4380
rpl_filter->add_ignore_db(argument);
4460
4383
case (int)OPT_REPLICATE_DO_DB:
4462
rpl_filter->add_do_db(argument);
4385
rpl_filter->add_do_db(argument);
4465
4388
case (int)OPT_REPLICATE_REWRITE_DB:
4467
char* key = argument,*p, *val;
4469
if (!(p= strstr(argument, "->")))
4472
"Bad syntax in replicate-rewrite-db - missing '->'!\n");
4476
while (my_isspace(mysqld_charset, *p) && p > argument)
4481
"Bad syntax in replicate-rewrite-db - empty FROM db!\n");
4486
while (*val && my_isspace(mysqld_charset, *val))
4491
"Bad syntax in replicate-rewrite-db - empty TO db!\n");
4495
rpl_filter->add_db_rewrite(key, val);
4390
char* key = argument,*p, *val;
4392
if (!(p= strstr(argument, "->")))
4395
"Bad syntax in replicate-rewrite-db - missing '->'!\n");
4399
while (my_isspace(mysqld_charset, *p) && p > argument)
4404
"Bad syntax in replicate-rewrite-db - empty FROM db!\n");
4409
while (*val && my_isspace(mysqld_charset, *val))
4414
"Bad syntax in replicate-rewrite-db - empty TO db!\n");
4418
rpl_filter->add_db_rewrite(key, val);
4499
4422
case (int)OPT_BINLOG_IGNORE_DB:
4501
binlog_filter->add_ignore_db(argument);
4424
binlog_filter->add_ignore_db(argument);
4504
4427
case OPT_BINLOG_FORMAT:
4507
id= find_type_or_exit(argument, &binlog_format_typelib, opt->name);
4508
global_system_variables.binlog_format= opt_binlog_format_id= id - 1;
4430
id= find_type_or_exit(argument, &binlog_format_typelib, opt->name);
4431
global_system_variables.binlog_format= opt_binlog_format_id= id - 1;
4511
4434
case (int)OPT_BINLOG_DO_DB:
4513
binlog_filter->add_do_db(argument);
4436
binlog_filter->add_do_db(argument);
4516
4439
case (int)OPT_REPLICATE_DO_TABLE:
4518
if (rpl_filter->add_do_table(argument))
4520
fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
4441
if (rpl_filter->add_do_table(argument))
4443
fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
4525
4448
case (int)OPT_REPLICATE_WILD_DO_TABLE:
4527
if (rpl_filter->add_wild_do_table(argument))
4529
fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
4450
if (rpl_filter->add_wild_do_table(argument))
4452
fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
4534
4457
case (int)OPT_REPLICATE_WILD_IGNORE_TABLE:
4536
if (rpl_filter->add_wild_ignore_table(argument))
4538
fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
4459
if (rpl_filter->add_wild_ignore_table(argument))
4461
fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
4543
4466
case (int)OPT_REPLICATE_IGNORE_TABLE:
4545
if (rpl_filter->add_ignore_table(argument))
4547
fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
4468
if (rpl_filter->add_ignore_table(argument))
4470
fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
4552
4475
case (int) OPT_SLOW_QUERY_LOG:
4553
4476
opt_slow_log= 1;
4555
4478
#ifdef WITH_CSV_STORAGE_ENGINE
4556
4479
case OPT_LOG_OUTPUT:
4558
if (!argument || !argument[0])
4560
log_output_options= LOG_FILE;
4561
log_output_str= log_output_typelib.type_names[1];
4481
if (!argument || !argument[0])
4483
log_output_options= LOG_FILE;
4484
log_output_str= log_output_typelib.type_names[1];
4488
log_output_str= argument;
4490
find_bit_type_or_exit(argument, &log_output_typelib, opt->name);
4565
log_output_str= argument;
4567
find_bit_type_or_exit(argument, &log_output_typelib, opt->name);
4572
4495
case (int) OPT_SKIP_NEW:
4573
4496
opt_specialflag|= SPECIAL_NO_NEW_FUNC;
4659
4579
charsets_dir = mysql_charsets_dir;
4661
4581
case OPT_TX_ISOLATION:
4664
type= find_type_or_exit(argument, &tx_isolation_typelib, opt->name);
4665
global_system_variables.tx_isolation= (type-1);
4584
type= find_type_or_exit(argument, &tx_isolation_typelib, opt->name);
4585
global_system_variables.tx_isolation= (type-1);
4668
4588
case OPT_MYISAM_RECOVER:
4672
myisam_recover_options= HA_RECOVER_DEFAULT;
4673
myisam_recover_options_str= myisam_recover_typelib.type_names[0];
4675
else if (!argument[0])
4677
myisam_recover_options= HA_RECOVER_NONE;
4678
myisam_recover_options_str= "OFF";
4682
myisam_recover_options_str=argument;
4683
myisam_recover_options=
4684
find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name);
4686
ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
4592
myisam_recover_options= HA_RECOVER_DEFAULT;
4593
myisam_recover_options_str= myisam_recover_typelib.type_names[0];
4595
else if (!argument[0])
4597
myisam_recover_options= HA_RECOVER_NONE;
4598
myisam_recover_options_str= "OFF";
4602
myisam_recover_options_str=argument;
4603
myisam_recover_options=
4604
find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name);
4606
ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
4689
4609
case OPT_TC_HEURISTIC_RECOVER:
4690
4610
tc_heuristic_recover= find_type_or_exit(argument,
4691
4611
&tc_heuristic_recover_typelib,
4694
4614
case OPT_MYISAM_STATS_METHOD:
4699
myisam_stats_method_str= argument;
4700
method= find_type_or_exit(argument, &myisam_stats_method_typelib,
4704
method_conv= MI_STATS_METHOD_IGNORE_NULLS;
4707
method_conv= MI_STATS_METHOD_NULLS_EQUAL;
4711
method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
4619
myisam_stats_method_str= argument;
4620
method= find_type_or_exit(argument, &myisam_stats_method_typelib,
4624
method_conv= MI_STATS_METHOD_IGNORE_NULLS;
4627
method_conv= MI_STATS_METHOD_NULLS_EQUAL;
4631
method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
4634
global_system_variables.myisam_stats_method= method_conv;
4714
global_system_variables.myisam_stats_method= method_conv;
4717
case OPT_LOWER_CASE_TABLE_NAMES:
4718
lower_case_table_names= argument ? atoi(argument) : 1;
4719
lower_case_table_names_used= 1;
5059
Check if file system used for databases is case insensitive.
5061
@param dir_name Directory to test
5064
-1 Don't know (Test failed)
5066
0 File system is case sensitive
5068
1 File system is case insensitive
5071
static int test_if_case_insensitive(const char *dir_name)
5075
char buff[FN_REFLEN], buff2[FN_REFLEN];
5076
struct stat stat_info;
5078
fn_format(buff, glob_hostname, dir_name, ".lower-test",
5079
MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
5080
fn_format(buff2, glob_hostname, dir_name, ".LOWER-TEST",
5081
MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
5082
(void) my_delete(buff2, MYF(0));
5083
if ((file= my_create(buff, 0666, O_RDWR, MYF(0))) < 0)
5085
sql_print_warning("Can't create test file %s", buff);
5088
my_close(file, MYF(0));
5089
if (!stat(buff2, &stat_info))
5090
result= 1; // Can access file
5091
(void) my_delete(buff, MYF(MY_WME));
5097
4974
Create file to store pid number.
5099
4976
static void create_pid_file()