21
21
#include <sys/stat.h>
23
23
#define ADMIN_VERSION "8.42"
24
#define MAX_MYSQL_VAR 256
25
24
#define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */
26
#define MAX_TRUNC_LENGTH 3
28
char *host= NULL, *user= 0, *opt_password= 0,
29
*default_charset= NULL;
30
char truncated_var_names[MAX_MYSQL_VAR][MAX_TRUNC_LENGTH];
31
char ex_var_names[MAX_MYSQL_VAR][FN_REFLEN];
32
uint64_t last_values[MAX_MYSQL_VAR];
33
static int interval=0;
34
static bool option_force=0,interrupted=0,new_line=0,
35
opt_compress=0, opt_relative=0, opt_verbose=0, opt_vertical=0,
36
tty_password= 0, opt_nobeep;
37
static bool debug_info_flag= 0, debug_check_flag= 0;
38
static uint tcp_port = 0, option_wait = 0, option_silent=0, nr_iterations;
39
static uint opt_count_iterations= 0, my_end_arg;
40
static ulong opt_connect_timeout, opt_shutdown_timeout;
41
static char * unix_port=0;
43
static uint opt_protocol=0;
26
char *host= NULL, *user= NULL, *opt_password= NULL;
27
static bool interrupted= false, opt_verbose= false,tty_password= false;
28
static uint8_t opt_protocol= MYSQL_PROTOCOL_TCP;
29
static uint32_t tcp_port= 0, option_wait= 0, option_silent= 0;
30
static uint32_t my_end_arg;
31
static uint32_t opt_connect_timeout, opt_shutdown_timeout;
44
32
static myf error_flags; /* flags to pass to my_printf_error, like ME_BELL */
47
When using extended-status relatively, ex_val_max_len is the estimated
48
maximum length for any relative value printed by extended-status. The
49
idea is to try to keep the length of output as short as possible.
52
static uint ex_val_max_len[MAX_MYSQL_VAR];
53
static bool ex_status_printed = 0; /* First output is not relative. */
54
static uint ex_var_count, max_var_length, max_val_length;
37
static void usage(void);
56
38
static void print_version(void);
57
static void usage(void);
39
extern "C" sig_handler endprog(int signal_number);
58
40
extern "C" bool get_one_option(int optid, const struct my_option *opt,
42
static int execute_commands(MYSQL *mysql,int argc, char **argv);
60
43
static bool sql_connect(MYSQL *mysql, uint wait);
61
static int execute_commands(MYSQL *mysql,int argc, char **argv);
62
static int drop_db(MYSQL *mysql,const char *db);
63
extern "C" sig_handler endprog(int signal_number);
64
static void nice_time(ulong sec,char *buff);
65
static void print_header(MYSQL_RES *result);
66
static void print_top(MYSQL_RES *result);
67
static void print_row(MYSQL_RES *result,MYSQL_ROW cur, uint row);
68
static void print_relative_row(MYSQL_RES *result, MYSQL_ROW cur, uint row);
69
static void print_relative_row_vert(MYSQL_RES *result, MYSQL_ROW cur, uint row);
70
static void print_relative_header();
71
static void print_relative_line();
72
static void truncate_names();
73
static bool get_pidfile(MYSQL *mysql, char *pidfile);
74
static bool wait_pidfile(char *pidfile, time_t last_modified,
75
struct stat *pidfile_status);
76
static void store_values(MYSQL_RES *result);
79
46
The order of commands must be the same as command_names,
84
ADMIN_CREATE, ADMIN_DROP, ADMIN_SHUTDOWN,
85
ADMIN_RELOAD, ADMIN_REFRESH, ADMIN_VER,
86
ADMIN_PROCESSLIST, ADMIN_STATUS, ADMIN_KILL,
87
ADMIN_DEBUG, ADMIN_VARIABLES, ADMIN_FLUSH_LOGS,
88
ADMIN_FLUSH_HOSTS, ADMIN_FLUSH_TABLES, ADMIN_PASSWORD,
89
ADMIN_PING, ADMIN_EXTENDED_STATUS, ADMIN_FLUSH_STATUS,
90
ADMIN_FLUSH_PRIVILEGES, ADMIN_START_SLAVE, ADMIN_STOP_SLAVE,
91
ADMIN_FLUSH_THREADS, ADMIN_OLD_PASSWORD
93
55
static const char *command_names[]= {
94
"create", "drop", "shutdown",
95
"reload", "refresh", "version",
96
"processlist", "status", "kill",
97
"debug", "variables", "flush-logs",
98
"flush-hosts", "flush-tables", "password",
99
"ping", "extended-status", "flush-status",
100
"flush-privileges", "start-slave", "stop-slave",
101
"flush-threads","old-password",
105
61
static TYPELIB command_typelib=
106
{ array_elements(command_names)-1,"commands", command_names, NULL};
62
{ array_elements(command_names)-1,"commands", command_names, NULL };
108
64
static struct my_option my_long_options[] =
111
"Number of iterations to make. This works with -i (--sleep) only.",
112
(char**) &nr_iterations, (char**) &nr_iterations, 0, GET_UINT,
113
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
114
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit .",
115
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
116
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
117
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
118
(char**) &debug_info_flag, (char**) &debug_info_flag,
119
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
121
"Don't ask for confirmation on drop database; with multiple commands, continue even if an error occurs.",
122
(char**) &option_force, (char**) &option_force, 0, GET_BOOL, NO_ARG, 0, 0,
124
{"compress", 'C', "Use compression in server/client protocol.",
125
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
127
{"character-sets-dir", OPT_CHARSETS_DIR,
128
"Directory where character sets are.", (char**) &charsets_dir,
129
(char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
130
{"default-character-set", OPT_DEFAULT_CHARSET,
131
"Set the default character set.", (char**) &default_charset,
132
(char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
133
66
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG,
134
67
NO_ARG, 0, 0, 0, 0, 0, 0},
135
68
{"host", 'h', "Connect to host.", (char**) &host, (char**) &host, 0, GET_STR,
136
69
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
137
{"no-beep", 'b', "Turn off beep on error.", (char**) &opt_nobeep,
138
(char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
140
71
"Password to use when connecting to server. If password is not given it's asked from the tty.",
141
72
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
147
78
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
148
79
(char**) &tcp_port,
149
80
(char**) &tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
150
{"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
151
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
153
"Show difference between current and previous values when used with -i. Currently works only with extended-status.",
154
(char**) &opt_relative, (char**) &opt_relative, 0, GET_BOOL, NO_ARG, 0, 0, 0,
156
{"set-variable", 'O',
157
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
158
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
159
81
{"silent", 's', "Silently exit if one can't connect to server.",
160
82
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
161
{"socket", 'S', "Socket file to use for connection.",
162
(char**) &unix_port, (char**) &unix_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
164
{"sleep", 'i', "Execute commands again and again with a sleep between.",
165
(char**) &interval, (char**) &interval, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0,
167
83
#ifndef DONT_ALLOW_USER_CHANGE
168
84
{"user", 'u', "User for login if not current user.", (char**) &user,
169
85
(char**) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
390
249
if (!option_silent)
393
host= (char*) LOCAL_HOST;
394
my_printf_error(0,"connect to server at '%s' failed\nerror: '%s'",
395
error_flags, host, mysql_error(mysql));
396
if (mysql_errno(mysql) == CR_CONNECTION_ERROR)
399
"Check that mysqld is running and that the socket: '%s' exists!\n",
400
unix_port ? unix_port : mysql_unix_port);
402
else if (mysql_errno(mysql) == CR_CONN_HOST_ERROR ||
403
mysql_errno(mysql) == CR_UNKNOWN_HOST)
405
fprintf(stderr,"Check that mysqld is running on %s",host);
406
fprintf(stderr," and that the port is %d.\n",
407
tcp_port ? tcp_port: mysql_port);
408
fprintf(stderr,"You can check this by doing 'telnet %s %d'\n",
409
host, tcp_port ? tcp_port: mysql_port);
252
host= (char*) LOCAL_HOST;
254
my_printf_error(0,"connect to server at '%s' failed\nerror: '%s'",
255
error_flags, host, mysql_error(mysql));
257
if (mysql_errno(mysql) == CR_CONN_HOST_ERROR ||
258
mysql_errno(mysql) == CR_UNKNOWN_HOST)
260
fprintf(stderr,"Check that drizzled is running on %s",host);
261
fprintf(stderr," and that the port is %d.\n",
262
tcp_port ? tcp_port: mysql_port);
263
fprintf(stderr,"You can check this by doing 'telnet %s %d'\n",
264
host, tcp_port ? tcp_port: mysql_port);
414
269
if (wait != (uint) ~0)
415
270
wait--; /* One less retry */
416
271
if ((mysql_errno(mysql) != CR_CONN_HOST_ERROR) &&
417
(mysql_errno(mysql) != CR_CONNECTION_ERROR))
272
(mysql_errno(mysql) != CR_CONNECTION_ERROR))
419
274
fprintf(stderr,"Got error: %s\n", mysql_error(mysql));
423
276
else if (!option_silent)
428
fputs("Waiting for MySQL server to answer",stderr);
429
(void) fflush(stderr);
281
fputs("Waiting for Drizzle server to answer",stderr);
282
(void) fflush(stderr);
434
(void) fflush(stderr);
287
(void) fflush(stderr);
443
295
Execute a command.
445
297
-1 on retryable error
449
300
static int execute_commands(MYSQL *mysql,int argc, char **argv)
453
304
MySQL documentation relies on the fact that mysqladmin will
454
execute commands in the order specified, e.g.
455
mysqladmin -u root flush-privileges password "newpassword"
456
to reset a lost root password.
305
execute commands in the order specified.
457
306
If this behaviour is ever changed, Docs should be notified.
460
struct rand_struct rand_st;
462
308
for (; argc > 0 ; argv++,argc--)
464
310
switch (find_type(argv[0],&command_typelib,2)) {
467
char buff[FN_REFLEN+20];
470
my_printf_error(0, "Too few arguments to create", error_flags);
473
sprintf(buff,"create database `%.*s`",FN_REFLEN,argv[1]);
474
if (mysql_query(mysql,buff))
476
my_printf_error(0,"CREATE DATABASE failed; error: '%-.200s'",
477
error_flags, mysql_error(mysql));
487
my_printf_error(0, "Too few arguments to drop", error_flags);
490
if (drop_db(mysql,argv[1]))
495
311
case ADMIN_SHUTDOWN:
497
char pidfile[FN_REFLEN];
499
time_t last_modified= 0;
500
struct stat pidfile_status;
503
Only wait for pidfile on local connections
504
If pidfile doesn't exist, continue without pid file checking
506
if (mysql->unix_socket && (got_pidfile= !get_pidfile(mysql, pidfile)) &&
507
!stat(pidfile, &pidfile_status))
508
last_modified= pidfile_status.st_mtime;
314
printf("shutting down drizzled...\n");
510
316
if (mysql_shutdown(mysql, SHUTDOWN_DEFAULT))
512
my_printf_error(0, "shutdown failed; error: '%s'", error_flags,
318
my_printf_error(0, "shutdown failed; error: '%s'", error_flags,
516
322
mysql_close(mysql); /* Close connection to avoid error messages */
517
argc=1; /* force SHUTDOWN to be the last command */
521
printf("Shutdown signal sent to server; Waiting for pid file to disappear\n");
523
/* Wait until pid file is gone */
524
if (wait_pidfile(pidfile, last_modified, &pidfile_status))
529
case ADMIN_FLUSH_PRIVILEGES:
531
if (mysql_query(mysql,"flush privileges"))
533
my_printf_error(0, "reload failed; error: '%s'", error_flags,
539
if (mysql_refresh(mysql,
540
(uint) ~(REFRESH_GRANT | REFRESH_STATUS |
541
REFRESH_READ_LOCK | REFRESH_SLAVE |
544
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
549
case ADMIN_FLUSH_THREADS:
550
if (mysql_refresh(mysql,(uint) REFRESH_THREADS))
552
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
560
puts("Copyright (C) 2000-2006 MySQL AB");
561
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
562
printf("Server version\t\t%s\n", mysql_get_server_info(mysql));
563
printf("Protocol version\t%d\n", mysql_get_proto_info(mysql));
564
printf("Connection\t\t%s\n",mysql_get_host_info(mysql));
565
if (mysql->unix_socket)
566
printf("UNIX socket\t\t%s\n", mysql->unix_socket);
568
printf("TCP port\t\t%d\n", mysql->port);
569
status=mysql_stat(mysql);
573
pos= (char*) strchr(status,' ');
575
printf("%s\t\t\t",status); /* print label */
576
if ((status=str2int(pos,10,0,LONG_MAX,(long*) &sec)))
579
puts(buff); /* print nice time */
580
while (*status == ' ') status++; /* to next info */
587
case ADMIN_PROCESSLIST:
592
if (mysql_query(mysql, (opt_verbose ? "show full processlist" :
593
"show processlist")) ||
594
!(result = mysql_store_result(mysql)))
596
my_printf_error(0, "process list failed; error: '%s'", error_flags,
600
print_header(result);
601
while ((row=mysql_fetch_row(result)))
602
print_row(result,row,0);
604
mysql_free_result(result);
609
status=mysql_stat(mysql);
619
my_printf_error(0, "Too few arguments to 'kill'", error_flags);
625
if (mysql_kill(mysql,(ulong) atol(pos)))
627
my_printf_error(0, "kill failed on %ld; error: '%s'", error_flags,
628
atol(pos), mysql_error(mysql));
631
if (!(pos=strchr(pos,',')))
641
if (mysql_dump_debug_info(mysql))
643
my_printf_error(0, "debug failed; error: '%s'", error_flags,
648
case ADMIN_VARIABLES:
654
if (mysql_query(mysql,"show /*!40003 GLOBAL */ variables") ||
655
!(res=mysql_store_result(mysql)))
657
my_printf_error(0, "unable to show variables; error: '%s'", error_flags,
662
while ((row=mysql_fetch_row(res)))
663
print_row(res,row,0);
665
mysql_free_result(res);
668
case ADMIN_EXTENDED_STATUS:
673
void (*func) (MYSQL_RES*, MYSQL_ROW, uint);
676
if (mysql_query(mysql, "show /*!50002 GLOBAL */ status") ||
677
!(res = mysql_store_result(mysql)))
679
my_printf_error(0, "unable to show status; error: '%s'", error_flags,
687
if (!ex_status_printed)
690
truncate_names(); /* Does some printing also */
694
print_relative_line();
695
print_relative_header();
696
print_relative_line();
700
/* void (*func) (MYSQL_RES*, MYSQL_ROW, uint); */
701
if (opt_relative && !opt_vertical)
702
func = print_relative_row;
703
else if (opt_vertical)
704
func = print_relative_row_vert;
708
while ((row = mysql_fetch_row(res)))
709
(*func)(res, row, rownr++);
712
if (ex_status_printed)
715
print_relative_line();
721
ex_status_printed = 1; /* From now on the output will be relative */
722
mysql_free_result(res);
725
case ADMIN_FLUSH_LOGS:
727
if (mysql_refresh(mysql,REFRESH_LOG))
729
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
735
case ADMIN_FLUSH_HOSTS:
737
if (mysql_query(mysql,"flush hosts"))
739
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
745
case ADMIN_FLUSH_TABLES:
747
if (mysql_query(mysql,"flush tables"))
749
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
755
case ADMIN_FLUSH_STATUS:
757
if (mysql_query(mysql,"flush status"))
759
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
765
case ADMIN_OLD_PASSWORD:
768
char buff[128],crypted_pw[64];
770
/* Do initialization the same way as we do in mysqld */
771
start_time=time((time_t*) 0);
772
randominit(&rand_st,(ulong) start_time,(ulong) start_time/2);
776
my_printf_error(0, "Too few arguments to change password", error_flags);
782
bool old= (find_type(argv[0], &command_typelib, 2) ==
785
If we don't already know to use an old-style password, see what
790
if (mysql_query(mysql, "SHOW VARIABLES LIKE 'old_passwords'"))
792
my_printf_error(0, "Could not determine old_passwords setting from server; error: '%s'",
793
error_flags, mysql_error(mysql));
798
MYSQL_RES *res= mysql_store_result(mysql);
802
"Could not get old_passwords setting from "
803
"server; error: '%s'",
804
error_flags, mysql_error(mysql));
807
if (!mysql_num_rows(res))
811
MYSQL_ROW row= mysql_fetch_row(res);
812
old= !strncmp(row[1], "ON", 2);
814
mysql_free_result(res);
818
make_scrambled_password_323(crypted_pw, pw);
820
make_scrambled_password(crypted_pw, pw);
823
crypted_pw[0]=0; /* No password */
824
sprintf(buff,"set password='%s',sql_log_off=0",crypted_pw);
826
if (mysql_query(mysql,"set sql_log_off=1"))
828
my_printf_error(0, "Can't turn off logging; error: '%s'",
829
error_flags, mysql_error(mysql));
832
if (mysql_query(mysql,buff))
834
if (mysql_errno(mysql)!=1290)
836
my_printf_error(0,"unable to change password; error: '%s'",
837
error_flags, mysql_error(mysql));
843
We don't try to execute 'update mysql.user set..'
844
because we can't perfectly find out the host
846
my_printf_error(0,"\n"
847
"You cannot use 'password' command as mysqld runs\n"
848
" with grant tables disabled (was started with"
849
" --skip-grant-tables).\n"
850
"Use: \"mysqladmin flush-privileges password '*'\""
851
" instead", error_flags);
859
case ADMIN_START_SLAVE:
860
if (mysql_query(mysql, "START SLAVE"))
862
my_printf_error(0, "Error starting slave: %s", error_flags,
867
puts("Slave started");
869
case ADMIN_STOP_SLAVE:
870
if (mysql_query(mysql, "STOP SLAVE"))
872
my_printf_error(0, "Error stopping slave: %s", error_flags,
877
puts("Slave stopped");
327
argc=1; /* Force SHUTDOWN to be the last command */
881
331
mysql->reconnect=0; /* We want to know of reconnects */
882
332
if (!mysql_ping(mysql))
884
if (option_silent < 2)
885
puts("mysqld is alive");
334
if (option_silent < 2)
335
puts("drizzled is alive");
889
if (mysql_errno(mysql) == CR_SERVER_GONE_ERROR)
892
if (!mysql_ping(mysql))
893
puts("connection was down, but mysqld is now alive");
897
my_printf_error(0,"mysqld doesn't answer to ping, error: '%s'",
898
error_flags, mysql_error(mysql));
339
if (mysql_errno(mysql) == CR_SERVER_GONE_ERROR)
342
if (!mysql_ping(mysql))
343
puts("connection was down, but drizzled is now alive");
347
my_printf_error(0,"drizzled doesn't answer to ping, error: '%s'",
348
error_flags, mysql_error(mysql));
902
352
mysql->reconnect=1; /* Automatic reconnect is default */
905
356
my_printf_error(0, "Unknown command: '%-.60s'", error_flags, argv[0]);
917
368
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
921
371
static void usage(void)
924
374
puts("Copyright (C) 2000-2006 MySQL AB");
925
375
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
926
puts("Administration program for the mysqld daemon.");
376
puts("Administration program for the drizzled daemon.");
927
377
printf("Usage: %s [OPTIONS] command command....\n", my_progname);
928
378
my_print_help(my_long_options);
929
my_print_variables(my_long_options);
930
print_defaults("my",load_default_groups);
931
puts("\nWhere command is a one or more of: (Commands may be shortened)\n\
932
create databasename Create a new database\n\
933
debug Instruct server to write debug information to log\n\
934
drop databasename Delete a database and all its tables\n\
935
extended-status Gives an extended status message from the server\n\
936
flush-hosts Flush all cached hosts\n\
937
flush-logs Flush all logs\n\
938
flush-status Clear status variables\n\
939
flush-tables Flush all tables\n\
940
flush-threads Flush the thread cache\n\
941
flush-privileges Reload grant tables (same as reload)\n\
942
kill id,id,... Kill mysql threads");
943
#if MYSQL_VERSION_ID >= 32200
945
password new-password Change old password to new-password, MySQL 4.1 hashing.\n\
946
old-password new-password Change old password to new-password in old format.\n");
949
ping Check if mysqld is alive\n\
950
processlist Show list of active threads in server\n\
951
reload Reload grant tables\n\
952
refresh Flush all tables and close and open logfiles\n\
953
shutdown Take server down\n\
954
status Gives a short status message from the server\n\
955
start-slave Start slave\n\
956
stop-slave Stop slave\n\
957
variables Prints variables available\n\
958
version Get version info from server");
380
ping Check if server is down\n\
381
shutdown Take server down\n");
961
384
#include <help_end.h>
963
static int drop_db(MYSQL *mysql, const char *db)
965
char name_buff[FN_REFLEN+20], buf[10];
968
puts("Dropping the database is potentially a very bad thing to do.");
969
puts("Any data stored in the database will be destroyed.\n");
970
printf("Do you really want to drop the '%s' database [y/N] ",db);
972
VOID(fgets(buf,sizeof(buf)-1,stdin));
973
if ((*buf != 'y') && (*buf != 'Y'))
975
puts("\nOK, aborting database drop!");
979
sprintf(name_buff,"drop database `%.*s`",FN_REFLEN,db);
980
if (mysql_query(mysql,name_buff))
982
my_printf_error(0, "DROP DATABASE %s failed;\nerror: '%s'", error_flags,
983
db,mysql_error(mysql));
986
printf("Database \"%s\" dropped\n",db);
991
static void nice_time(ulong sec,char *buff)
999
buff=int10_to_str(tmp, buff, 10);
1000
buff=strmov(buff,tmp > 1 ? " days " : " day ");
1006
buff=int10_to_str(tmp, buff, 10);
1007
buff=strmov(buff,tmp > 1 ? " hours " : " hour ");
1013
buff=int10_to_str(tmp, buff, 10);
1014
buff=strmov(buff," min ");
1016
strmov(int10_to_str(sec, buff, 10)," sec");
1020
static void print_header(MYSQL_RES *result)
1025
mysql_field_seek(result,0);
1027
while ((field = mysql_fetch_field(result)))
1029
printf(" %-*s|",(int) field->max_length+1,field->name);
1036
static void print_top(MYSQL_RES *result)
1042
mysql_field_seek(result,0);
1043
while((field = mysql_fetch_field(result)))
1045
if ((length=(uint) strlen(field->name)) > field->max_length)
1046
field->max_length=length;
1048
length=field->max_length;
1049
for (i=length+2 ; i--> 0 ; )
1057
/* 3.rd argument, uint row, is not in use. Don't remove! */
1058
static void print_row(MYSQL_RES *result, MYSQL_ROW cur,
1059
uint row __attribute__((unused)))
1065
mysql_field_seek(result,0);
1066
for (i=0 ; i < mysql_num_fields(result); i++)
1068
field = mysql_fetch_field(result);
1069
length=field->max_length;
1070
printf(" %-*s|",length+1,cur[i] ? (char*) cur[i] : "");
1076
static void print_relative_row(MYSQL_RES *result, MYSQL_ROW cur, uint row)
1082
mysql_field_seek(result, 0);
1083
field = mysql_fetch_field(result);
1084
printf("| %-*s|", (int) field->max_length + 1, cur[0]);
1086
field = mysql_fetch_field(result);
1087
tmp = cur[1] ? strtoull(cur[1], NULL, 10) : (uint64_t) 0;
1088
printf(" %-*s|\n", (int) field->max_length + 1,
1089
llstr((tmp - last_values[row]), buff));
1090
last_values[row] = tmp;
1094
static void print_relative_row_vert(MYSQL_RES *result __attribute__((unused)),
1096
uint row __attribute__((unused)))
1105
tmp = cur[1] ? strtoull(cur[1], NULL, 10) : (uint64_t) 0;
1106
printf(" %-*s|", ex_val_max_len[row] + 1,
1107
llstr((tmp - last_values[row]), buff));
1109
/* Find the minimum row length needed to output the relative value */
1110
if ((length=(uint) strlen(buff) > ex_val_max_len[row]) && ex_status_printed)
1111
ex_val_max_len[row] = length;
1112
last_values[row] = tmp;
1116
static void store_values(MYSQL_RES *result)
1122
field = mysql_fetch_field(result);
1123
max_var_length = field->max_length;
1124
field = mysql_fetch_field(result);
1125
max_val_length = field->max_length;
1127
for (i = 0; (row = mysql_fetch_row(result)); i++)
1129
strmov(ex_var_names[i], row[0]);
1130
last_values[i]=strtoull(row[1],NULL,10);
1131
ex_val_max_len[i]=2; /* Default print width for values */
1138
static void print_relative_header()
1143
for (i = 0; i < ex_var_count; i++)
1144
printf(" %-*s|", ex_val_max_len[i] + 1, truncated_var_names[i]);
1149
static void print_relative_line()
1154
for (i = 0; i < ex_var_count; i++)
1157
for (j = 0; j < ex_val_max_len[i] + 2; j++)
1165
static void truncate_names()
1168
char *ptr,top_line[MAX_TRUNC_LENGTH+4+NAME_LEN+22+1],buff[22];
1172
ptr=strfill(ptr,max_var_length+2,'-');
1174
ptr=strfill(ptr,MAX_TRUNC_LENGTH+2,'-');
1176
ptr=strfill(ptr,max_val_length+2,'-');
1181
for (i = 0 ; i < ex_var_count; i++)
1184
printf("| %-*s|", max_var_length + 1, ex_var_names[i]);
1185
ptr = ex_var_names[i];
1186
/* Make sure no two same truncated names will become */
1187
for (j = 0; j < i; j++)
1188
if (*truncated_var_names[j] == *ptr)
1191
truncated_var_names[i][0]= *ptr; /* Copy first var char */
1192
int10_to_str(sfx, truncated_var_names[i]+1,10);
1193
printf(" %-*s|", MAX_TRUNC_LENGTH + 1, truncated_var_names[i]);
1194
printf(" %-*s|\n", max_val_length + 1, llstr(last_values[i],buff));
1201
static bool get_pidfile(MYSQL *mysql, char *pidfile)
1205
if (mysql_query(mysql, "SHOW VARIABLES LIKE 'pid_file'"))
1207
my_printf_error(0, "query failed; error: '%s'", error_flags,
1208
mysql_error(mysql));
1210
result = mysql_store_result(mysql);
1213
MYSQL_ROW row=mysql_fetch_row(result);
1215
strmov(pidfile, row[1]);
1216
mysql_free_result(result);
1217
return row == 0; /* Error if row = 0 */
1219
return 1; /* Error */
1223
Return 1 if pid file didn't disappear or change
1226
static bool wait_pidfile(char *pidfile, time_t last_modified,
1227
struct stat *pidfile_status)
1229
char buff[FN_REFLEN];
1234
system_filename(buff, pidfile);
1238
if ((fd= my_open(buff, O_RDONLY, MYF(0))) < 0)
1243
(void) my_close(fd,MYF(0));
1244
if (last_modified && !stat(pidfile, pidfile_status))
1246
if (last_modified != pidfile_status->st_mtime)
1248
/* File changed; Let's assume that mysqld did restart */
1250
printf("pid file '%s' changed while waiting for it to disappear!\nmysqld did probably restart\n",
1256
if (count++ == opt_shutdown_timeout)
1259
} while (!interrupted);
1264
"Warning; Aborted waiting on pid file: '%s' after %d seconds\n",