1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 MySQL
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
/* maintaince of drizzle databases */
1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* maintaince of mysql databases */
23
18
#include "client_priv.h"
24
19
#include <signal.h>
25
#include <mysys/my_pthread.h> /* because of signal() */
21
#include <my_pthread.h> /* because of signal() */
26
23
#include <sys/stat.h>
28
/* Added this for string translation. */
29
#include <libdrizzle/gettext.h>
26
#ifdef LATER_HAVE_NDBCLUSTER_DB
27
#include "../ndb/src/mgmclient/ndb_mgmclient.h"
31
30
#define ADMIN_VERSION "8.42"
31
#define MAX_MYSQL_VAR 256
32
32
#define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */
34
char *host= NULL, *user= NULL, *opt_password= NULL;
35
static bool interrupted= false, opt_verbose= false,tty_password= false;
36
static uint32_t tcp_port= 0, option_wait= 0, option_silent= 0;
37
static uint32_t my_end_arg;
38
static uint32_t opt_connect_timeout, opt_shutdown_timeout;
33
#define MAX_TRUNC_LENGTH 3
35
char *host= NULL, *user= 0, *opt_password= 0,
36
*default_charset= NULL;
37
char truncated_var_names[MAX_MYSQL_VAR][MAX_TRUNC_LENGTH];
38
char ex_var_names[MAX_MYSQL_VAR][FN_REFLEN];
39
ulonglong last_values[MAX_MYSQL_VAR];
40
static int interval=0;
41
static my_bool option_force=0,interrupted=0,new_line=0,
42
opt_compress=0, opt_relative=0, opt_verbose=0, opt_vertical=0,
43
tty_password= 0, opt_nobeep;
44
static my_bool debug_info_flag= 0, debug_check_flag= 0;
45
static uint tcp_port = 0, option_wait = 0, option_silent=0, nr_iterations;
46
static uint opt_count_iterations= 0, my_end_arg;
47
static ulong opt_connect_timeout, opt_shutdown_timeout;
48
static char * unix_port=0;
49
#ifdef LATER_HAVE_NDBCLUSTER_DB
50
static my_bool opt_ndbcluster=0;
51
static char *opt_ndb_connectstring=0;
55
static char *shared_memory_base_name=0;
57
static uint opt_protocol=0;
39
58
static myf error_flags; /* flags to pass to my_printf_error, like ME_BELL */
61
When using extended-status relatively, ex_val_max_len is the estimated
62
maximum length for any relative value printed by extended-status. The
63
idea is to try to keep the length of output as short as possible.
66
static uint ex_val_max_len[MAX_MYSQL_VAR];
67
static my_bool ex_status_printed = 0; /* First output is not relative. */
68
static uint ex_var_count, max_var_length, max_val_length;
70
static void print_version(void);
44
71
static void usage(void);
45
static void print_version(void);
46
extern "C" RETSIGTYPE endprog(int signal_number);
47
extern "C" bool get_one_option(int optid, const struct my_option *opt,
49
static int execute_commands(DRIZZLE *drizzle,int argc, char **argv);
50
static bool sql_connect(DRIZZLE *drizzle, uint wait);
72
extern "C" my_bool get_one_option(int optid, const struct my_option *opt,
74
static my_bool sql_connect(MYSQL *mysql, uint wait);
75
static int execute_commands(MYSQL *mysql,int argc, char **argv);
76
static int drop_db(MYSQL *mysql,const char *db);
77
extern "C" sig_handler endprog(int signal_number);
78
static void nice_time(ulong sec,char *buff);
79
static void print_header(MYSQL_RES *result);
80
static void print_top(MYSQL_RES *result);
81
static void print_row(MYSQL_RES *result,MYSQL_ROW cur, uint row);
82
static void print_relative_row(MYSQL_RES *result, MYSQL_ROW cur, uint row);
83
static void print_relative_row_vert(MYSQL_RES *result, MYSQL_ROW cur, uint row);
84
static void print_relative_header();
85
static void print_relative_line();
86
static void truncate_names();
87
static my_bool get_pidfile(MYSQL *mysql, char *pidfile);
88
static my_bool wait_pidfile(char *pidfile, time_t last_modified,
89
struct stat *pidfile_status);
90
static void store_values(MYSQL_RES *result);
53
93
The order of commands must be the same as command_names,
98
ADMIN_CREATE, ADMIN_DROP, ADMIN_SHUTDOWN,
99
ADMIN_RELOAD, ADMIN_REFRESH, ADMIN_VER,
100
ADMIN_PROCESSLIST, ADMIN_STATUS, ADMIN_KILL,
101
ADMIN_DEBUG, ADMIN_VARIABLES, ADMIN_FLUSH_LOGS,
102
ADMIN_FLUSH_HOSTS, ADMIN_FLUSH_TABLES, ADMIN_PASSWORD,
103
ADMIN_PING, ADMIN_EXTENDED_STATUS, ADMIN_FLUSH_STATUS,
104
ADMIN_FLUSH_PRIVILEGES, ADMIN_START_SLAVE, ADMIN_STOP_SLAVE,
105
ADMIN_FLUSH_THREADS, ADMIN_OLD_PASSWORD
106
#ifdef LATER_HAVE_NDBCLUSTER_DB
62
110
static const char *command_names[]= {
111
"create", "drop", "shutdown",
112
"reload", "refresh", "version",
113
"processlist", "status", "kill",
114
"debug", "variables", "flush-logs",
115
"flush-hosts", "flush-tables", "password",
116
"ping", "extended-status", "flush-status",
117
"flush-privileges", "start-slave", "stop-slave",
118
"flush-threads","old-password",
119
#ifdef LATER_HAVE_NDBCLUSTER_DB
68
125
static TYPELIB command_typelib=
69
{ array_elements(command_names)-1,"commands", command_names, NULL };
126
{ array_elements(command_names)-1,"commands", command_names, NULL};
71
128
static struct my_option my_long_options[] =
73
{"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG,
131
"Number of iterations to make. This works with -i (--sleep) only.",
132
(uchar**) &nr_iterations, (uchar**) &nr_iterations, 0, GET_UINT,
133
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
135
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.",
136
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
138
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit .",
139
(uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
140
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
141
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
142
(uchar**) &debug_info_flag, (uchar**) &debug_info_flag,
143
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
145
"Don't ask for confirmation on drop database; with multiple commands, continue even if an error occurs.",
146
(uchar**) &option_force, (uchar**) &option_force, 0, GET_BOOL, NO_ARG, 0, 0,
148
{"compress", 'C', "Use compression in server/client protocol.",
149
(uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
151
{"character-sets-dir", OPT_CHARSETS_DIR,
152
"Directory where character sets are.", (uchar**) &charsets_dir,
153
(uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
154
{"default-character-set", OPT_DEFAULT_CHARSET,
155
"Set the default character set.", (uchar**) &default_charset,
156
(uchar**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
157
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG,
74
158
NO_ARG, 0, 0, 0, 0, 0, 0},
75
{"host", 'h', N_("Connect to host."), (char**) &host, (char**) &host, 0, GET_STR,
159
{"host", 'h', "Connect to host.", (uchar**) &host, (uchar**) &host, 0, GET_STR,
76
160
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
161
{"no-beep", 'b', "Turn off beep on error.", (uchar**) &opt_nobeep,
162
(uchar**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
78
N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
164
"Password to use when connecting to server. If password is not given it's asked from the tty.",
79
165
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
80
{"port", 'P', N_("Port number to use for connection or 0 for default to, in "
81
"order of preference, my.cnf, $DRIZZLE_TCP_PORT, "
82
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ")."),
84
(char**) &tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
85
{"silent", 's', N_("Silently exit if one can't connect to server."),
166
{"port", 'P', "Port number to use for connection or 0 for default to, in "
167
"order of preference, my.cnf, $MYSQL_TCP_PORT, "
168
#if MYSQL_PORT_DEFAULT == 0
171
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
173
(uchar**) &tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
174
{"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
175
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
177
"Show difference between current and previous values when used with -i. Currently works only with extended-status.",
178
(uchar**) &opt_relative, (uchar**) &opt_relative, 0, GET_BOOL, NO_ARG, 0, 0, 0,
180
{"set-variable", 'O',
181
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
182
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
184
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
185
"Base name of shared memory.", (uchar**) &shared_memory_base_name, (uchar**) &shared_memory_base_name,
186
0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
188
{"silent", 's', "Silently exit if one can't connect to server.",
86
189
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
190
{"socket", 'S', "Socket file to use for connection.",
191
(uchar**) &unix_port, (uchar**) &unix_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
193
{"sleep", 'i', "Execute commands again and again with a sleep between.",
194
(uchar**) &interval, (uchar**) &interval, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0,
87
196
#ifndef DONT_ALLOW_USER_CHANGE
88
{"user", 'u', N_("User for login if not current user."), (char**) &user,
89
(char**) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
197
{"user", 'u', "User for login if not current user.", (uchar**) &user,
198
(uchar**) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
91
{"verbose", 'v', N_("Write more information."), (char**) &opt_verbose,
92
(char**) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
93
{"version", 'V', N_("Output version information and exit."), 0, 0, 0, GET_NO_ARG,
200
{"verbose", 'v', "Write more information.", (uchar**) &opt_verbose,
201
(uchar**) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
202
{"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
94
203
NO_ARG, 0, 0, 0, 0, 0, 0},
95
{"wait", 'w', N_("Wait and retry if connection is down."), 0, 0, 0, GET_UINT,
205
"Print output vertically. Is similar to --relative, but prints output vertically.",
206
(uchar**) &opt_vertical, (uchar**) &opt_vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0,
208
{"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_UINT,
96
209
OPT_ARG, 0, 0, 0, 0, 0, 0},
97
{"connect_timeout", OPT_CONNECT_TIMEOUT, "", (char**) &opt_connect_timeout,
98
(char**) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 3600*12, 0,
210
{"connect_timeout", OPT_CONNECT_TIMEOUT, "", (uchar**) &opt_connect_timeout,
211
(uchar**) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 3600*12, 0,
99
212
3600*12, 0, 1, 0},
100
{"shutdown_timeout", OPT_SHUTDOWN_TIMEOUT, "", (char**) &opt_shutdown_timeout,
101
(char**) &opt_shutdown_timeout, 0, GET_ULONG, REQUIRED_ARG,
213
{"shutdown_timeout", OPT_SHUTDOWN_TIMEOUT, "", (uchar**) &opt_shutdown_timeout,
214
(uchar**) &opt_shutdown_timeout, 0, GET_ULONG, REQUIRED_ARG,
102
215
SHUTDOWN_DEF_TIMEOUT, 0, 3600*12, 0, 1, 0},
216
#ifdef LATER_HAVE_NDBCLUSTER_DB
217
{"ndbcluster", OPT_NDBCLUSTER, ""
218
"", (uchar**) &opt_ndbcluster,
219
(uchar**) &opt_ndbcluster, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
220
{"ndb-connectstring", OPT_NDB_CONNECTSTRING, ""
221
"", (uchar**) &opt_ndb_connectstring,
222
(uchar**) &opt_ndb_connectstring, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
103
224
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
107
static const char *load_default_groups[]= { "drizzleadmin","client",0 };
228
static const char *load_default_groups[]= { "mysqladmin","client",0 };
110
231
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
238
opt_count_iterations= 1;
119
243
char *start=argument;
121
opt_password= my_strdup(argument,MYF(MY_FAE));
122
while (*argument) *argument++= 'x'; /* Destroy argument */
244
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
245
opt_password=my_strdup(argument,MYF(MY_FAE));
246
while (*argument) *argument++= 'x'; /* Destroy argument */
124
start[1]=0; /* Cut length of argument */
248
start[1]=0; /* Cut length of argument */
258
DBUG_PUSH(argument ? argument : "d:t:o,/tmp/mysqladmin.trace");
251
445
if (!option_silent)
254
host= (char*) LOCAL_HOST;
256
my_printf_error(0,_("connect to server at '%s' failed\nerror: '%s'"),
257
error_flags, host, drizzle_error(drizzle));
259
if (drizzle_errno(drizzle) == CR_CONN_HOST_ERROR ||
260
drizzle_errno(drizzle) == CR_UNKNOWN_HOST)
262
fprintf(stderr,_("Check that drizzled is running on %s"),host);
263
fprintf(stderr,_(" and that the port is %d.\n"),
264
tcp_port ? tcp_port: drizzle_get_default_port());
265
fprintf(stderr,_("You can check this by doing 'telnet %s %d'\n"),
266
host, tcp_port ? tcp_port: drizzle_get_default_port());
448
host= (char*) LOCAL_HOST;
449
my_printf_error(0,"connect to server at '%s' failed\nerror: '%s'",
450
error_flags, host, mysql_error(mysql));
451
if (mysql_errno(mysql) == CR_CONNECTION_ERROR)
454
"Check that mysqld is running and that the socket: '%s' exists!\n",
455
unix_port ? unix_port : mysql_unix_port);
457
else if (mysql_errno(mysql) == CR_CONN_HOST_ERROR ||
458
mysql_errno(mysql) == CR_UNKNOWN_HOST)
460
fprintf(stderr,"Check that mysqld is running on %s",host);
461
fprintf(stderr," and that the port is %d.\n",
462
tcp_port ? tcp_port: mysql_port);
463
fprintf(stderr,"You can check this by doing 'telnet %s %d'\n",
464
host, tcp_port ? tcp_port: mysql_port);
271
if (wait != UINT32_MAX)
469
if (wait != (uint) ~0)
272
470
wait--; /* One less retry */
273
if ((drizzle_errno(drizzle) != CR_CONN_HOST_ERROR) &&
274
(drizzle_errno(drizzle) != CR_CONNECTION_ERROR))
471
if ((mysql_errno(mysql) != CR_CONN_HOST_ERROR) &&
472
(mysql_errno(mysql) != CR_CONNECTION_ERROR))
276
fprintf(stderr,_("Got error: %s\n"), drizzle_error(drizzle));
474
fprintf(stderr,"Got error: %s\n", mysql_error(mysql));
278
478
else if (!option_silent)
283
fputs(_("Waiting for Drizzle server to answer"),stderr);
284
(void) fflush(stderr);
483
fputs("Waiting for MySQL server to answer",stderr);
484
(void) fflush(stderr);
289
(void) fflush(stderr);
489
(void) fflush(stderr);
297
498
Execute a command.
299
500
-1 on retryable error
302
static int execute_commands(DRIZZLE *drizzle,int argc, char **argv)
504
static int execute_commands(MYSQL *mysql,int argc, char **argv)
306
DRIZZLE documentation relies on the fact that drizzleadmin will
307
execute commands in the order specified.
508
MySQL documentation relies on the fact that mysqladmin will
509
execute commands in the order specified, e.g.
510
mysqladmin -u root flush-privileges password "newpassword"
511
to reset a lost root password.
308
512
If this behaviour is ever changed, Docs should be notified.
515
struct rand_struct rand_st;
310
517
for (; argc > 0 ; argv++,argc--)
312
519
switch (find_type(argv[0],&command_typelib,2)) {
522
char buff[FN_REFLEN+20];
525
my_printf_error(0, "Too few arguments to create", error_flags);
528
sprintf(buff,"create database `%.*s`",FN_REFLEN,argv[1]);
529
if (mysql_query(mysql,buff))
531
my_printf_error(0,"CREATE DATABASE failed; error: '%-.200s'",
532
error_flags, mysql_error(mysql));
542
my_printf_error(0, "Too few arguments to drop", error_flags);
545
if (drop_db(mysql,argv[1]))
313
550
case ADMIN_SHUTDOWN:
316
printf(_("shutting down drizzled...\n"));
318
if (drizzle_shutdown(drizzle))
320
my_printf_error(0, _("shutdown failed; error: '%s'"), error_flags,
321
drizzle_error(drizzle));
324
drizzle_close(drizzle); /* Close connection to avoid error messages */
329
argc=1; /* Force SHUTDOWN to be the last command */
552
char pidfile[FN_REFLEN];
553
my_bool got_pidfile= 0;
554
time_t last_modified= 0;
555
struct stat pidfile_status;
558
Only wait for pidfile on local connections
559
If pidfile doesn't exist, continue without pid file checking
561
if (mysql->unix_socket && (got_pidfile= !get_pidfile(mysql, pidfile)) &&
562
!stat(pidfile, &pidfile_status))
563
last_modified= pidfile_status.st_mtime;
565
if (mysql_shutdown(mysql, SHUTDOWN_DEFAULT))
567
my_printf_error(0, "shutdown failed; error: '%s'", error_flags,
571
mysql_close(mysql); /* Close connection to avoid error messages */
572
argc=1; /* force SHUTDOWN to be the last command */
576
printf("Shutdown signal sent to server; Waiting for pid file to disappear\n");
578
/* Wait until pid file is gone */
579
if (wait_pidfile(pidfile, last_modified, &pidfile_status))
584
case ADMIN_FLUSH_PRIVILEGES:
586
if (mysql_query(mysql,"flush privileges"))
588
my_printf_error(0, "reload failed; error: '%s'", error_flags,
594
if (mysql_refresh(mysql,
595
(uint) ~(REFRESH_GRANT | REFRESH_STATUS |
596
REFRESH_READ_LOCK | REFRESH_SLAVE |
599
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
604
case ADMIN_FLUSH_THREADS:
605
if (mysql_refresh(mysql,(uint) REFRESH_THREADS))
607
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
615
puts("Copyright (C) 2000-2006 MySQL AB");
616
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");
617
printf("Server version\t\t%s\n", mysql_get_server_info(mysql));
618
printf("Protocol version\t%d\n", mysql_get_proto_info(mysql));
619
printf("Connection\t\t%s\n",mysql_get_host_info(mysql));
620
if (mysql->unix_socket)
621
printf("UNIX socket\t\t%s\n", mysql->unix_socket);
623
printf("TCP port\t\t%d\n", mysql->port);
624
status=mysql_stat(mysql);
628
pos= (char*) strchr(status,' ');
630
printf("%s\t\t\t",status); /* print label */
631
if ((status=str2int(pos,10,0,LONG_MAX,(long*) &sec)))
634
puts(buff); /* print nice time */
635
while (*status == ' ') status++; /* to next info */
642
case ADMIN_PROCESSLIST:
647
if (mysql_query(mysql, (opt_verbose ? "show full processlist" :
648
"show processlist")) ||
649
!(result = mysql_store_result(mysql)))
651
my_printf_error(0, "process list failed; error: '%s'", error_flags,
655
print_header(result);
656
while ((row=mysql_fetch_row(result)))
657
print_row(result,row,0);
659
mysql_free_result(result);
664
status=mysql_stat(mysql);
674
my_printf_error(0, "Too few arguments to 'kill'", error_flags);
680
if (mysql_kill(mysql,(ulong) atol(pos)))
682
my_printf_error(0, "kill failed on %ld; error: '%s'", error_flags,
683
atol(pos), mysql_error(mysql));
686
if (!(pos=strchr(pos,',')))
696
if (mysql_dump_debug_info(mysql))
698
my_printf_error(0, "debug failed; error: '%s'", error_flags,
703
case ADMIN_VARIABLES:
709
if (mysql_query(mysql,"show /*!40003 GLOBAL */ variables") ||
710
!(res=mysql_store_result(mysql)))
712
my_printf_error(0, "unable to show variables; error: '%s'", error_flags,
717
while ((row=mysql_fetch_row(res)))
718
print_row(res,row,0);
720
mysql_free_result(res);
723
case ADMIN_EXTENDED_STATUS:
728
void (*func) (MYSQL_RES*, MYSQL_ROW, uint);
731
if (mysql_query(mysql, "show /*!50002 GLOBAL */ status") ||
732
!(res = mysql_store_result(mysql)))
734
my_printf_error(0, "unable to show status; error: '%s'", error_flags,
742
if (!ex_status_printed)
745
truncate_names(); /* Does some printing also */
749
print_relative_line();
750
print_relative_header();
751
print_relative_line();
755
/* void (*func) (MYSQL_RES*, MYSQL_ROW, uint); */
756
if (opt_relative && !opt_vertical)
757
func = print_relative_row;
758
else if (opt_vertical)
759
func = print_relative_row_vert;
763
while ((row = mysql_fetch_row(res)))
764
(*func)(res, row, rownr++);
767
if (ex_status_printed)
770
print_relative_line();
776
ex_status_printed = 1; /* From now on the output will be relative */
777
mysql_free_result(res);
780
case ADMIN_FLUSH_LOGS:
782
if (mysql_refresh(mysql,REFRESH_LOG))
784
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
790
case ADMIN_FLUSH_HOSTS:
792
if (mysql_query(mysql,"flush hosts"))
794
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
800
case ADMIN_FLUSH_TABLES:
802
if (mysql_query(mysql,"flush tables"))
804
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
810
case ADMIN_FLUSH_STATUS:
812
if (mysql_query(mysql,"flush status"))
814
my_printf_error(0, "refresh failed; error: '%s'", error_flags,
820
case ADMIN_OLD_PASSWORD:
823
char buff[128],crypted_pw[64];
825
/* Do initialization the same way as we do in mysqld */
826
start_time=time((time_t*) 0);
827
randominit(&rand_st,(ulong) start_time,(ulong) start_time/2);
831
my_printf_error(0, "Too few arguments to change password", error_flags);
837
bool old= (find_type(argv[0], &command_typelib, 2) ==
840
If we don't already know to use an old-style password, see what
845
if (mysql_query(mysql, "SHOW VARIABLES LIKE 'old_passwords'"))
847
my_printf_error(0, "Could not determine old_passwords setting from server; error: '%s'",
848
error_flags, mysql_error(mysql));
853
MYSQL_RES *res= mysql_store_result(mysql);
857
"Could not get old_passwords setting from "
858
"server; error: '%s'",
859
error_flags, mysql_error(mysql));
862
if (!mysql_num_rows(res))
866
MYSQL_ROW row= mysql_fetch_row(res);
867
old= !strncmp(row[1], "ON", 2);
869
mysql_free_result(res);
873
make_scrambled_password_323(crypted_pw, pw);
875
make_scrambled_password(crypted_pw, pw);
878
crypted_pw[0]=0; /* No password */
879
sprintf(buff,"set password='%s',sql_log_off=0",crypted_pw);
881
if (mysql_query(mysql,"set sql_log_off=1"))
883
my_printf_error(0, "Can't turn off logging; error: '%s'",
884
error_flags, mysql_error(mysql));
887
if (mysql_query(mysql,buff))
889
if (mysql_errno(mysql)!=1290)
891
my_printf_error(0,"unable to change password; error: '%s'",
892
error_flags, mysql_error(mysql));
898
We don't try to execute 'update mysql.user set..'
899
because we can't perfectly find out the host
901
my_printf_error(0,"\n"
902
"You cannot use 'password' command as mysqld runs\n"
903
" with grant tables disabled (was started with"
904
" --skip-grant-tables).\n"
905
"Use: \"mysqladmin flush-privileges password '*'\""
906
" instead", error_flags);
914
case ADMIN_START_SLAVE:
915
if (mysql_query(mysql, "START SLAVE"))
917
my_printf_error(0, "Error starting slave: %s", error_flags,
922
puts("Slave started");
924
case ADMIN_STOP_SLAVE:
925
if (mysql_query(mysql, "STOP SLAVE"))
927
my_printf_error(0, "Error stopping slave: %s", error_flags,
932
puts("Slave stopped");
333
drizzle->reconnect=0; /* We want to know of reconnects */
334
if (!drizzle_ping(drizzle))
936
mysql->reconnect=0; /* We want to know of reconnects */
937
if (!mysql_ping(mysql))
336
if (option_silent < 2)
337
puts(_("drizzled is alive"));
939
if (option_silent < 2)
940
puts("mysqld is alive");
341
if (drizzle_errno(drizzle) == CR_SERVER_GONE_ERROR)
343
drizzle->reconnect=1;
344
if (!drizzle_ping(drizzle))
345
puts(_("connection was down, but drizzled is now alive"));
349
my_printf_error(0,_("drizzled doesn't answer to ping, error: '%s'"),
350
error_flags, drizzle_error(drizzle));
944
if (mysql_errno(mysql) == CR_SERVER_GONE_ERROR)
947
if (!mysql_ping(mysql))
948
puts("connection was down, but mysqld is now alive");
952
my_printf_error(0,"mysqld doesn't answer to ping, error: '%s'",
953
error_flags, mysql_error(mysql));
354
drizzle->reconnect=1; /* Automatic reconnect is default */
957
mysql->reconnect=1; /* Automatic reconnect is default */
959
#ifdef LATER_HAVE_NDBCLUSTER_DB
964
my_printf_error(0, "Too few arguments to ndb-mgm", error_flags);
968
Ndb_mgmclient_handle cmd=
969
ndb_mgmclient_handle_create(opt_ndb_connectstring);
970
ndb_mgmclient_execute(cmd, --argc, ++argv);
971
ndb_mgmclient_handle_destroy(cmd);
358
my_printf_error(0, _("Unknown command: '%-.60s'"), error_flags, argv[0]);
978
my_printf_error(0, "Unknown command: '%-.60s'", error_flags, argv[0]);
985
#include <help_start.h>
365
987
static void print_version(void)
367
printf(_("%s Ver %s Distrib %s, for %s on %s\n"),my_progname,ADMIN_VERSION,
368
drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
989
printf("%s Ver %s Distrib %s, for %s on %s\n",my_progname,ADMIN_VERSION,
990
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
371
994
static void usage(void)
374
puts(_("Copyright (C) 2000-2008 MySQL AB"));
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"));
376
puts(_("Administration program for the drizzled daemon."));
377
printf(_("Usage: %s [OPTIONS] command command....\n"), my_progname);
997
puts("Copyright (C) 2000-2006 MySQL AB");
998
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");
999
puts("Administration program for the mysqld daemon.");
1000
printf("Usage: %s [OPTIONS] command command....\n", my_progname);
378
1001
my_print_help(my_long_options);
380
ping Check if server is down\n\
381
shutdown Take server down\n"));
1002
my_print_variables(my_long_options);
1003
print_defaults("my",load_default_groups);
1004
puts("\nWhere command is a one or more of: (Commands may be shortened)\n\
1005
create databasename Create a new database\n\
1006
debug Instruct server to write debug information to log\n\
1007
drop databasename Delete a database and all its tables\n\
1008
extended-status Gives an extended status message from the server\n\
1009
flush-hosts Flush all cached hosts\n\
1010
flush-logs Flush all logs\n\
1011
flush-status Clear status variables\n\
1012
flush-tables Flush all tables\n\
1013
flush-threads Flush the thread cache\n\
1014
flush-privileges Reload grant tables (same as reload)\n\
1015
kill id,id,... Kill mysql threads");
1016
#if MYSQL_VERSION_ID >= 32200
1018
password new-password Change old password to new-password, MySQL 4.1 hashing.\n\
1019
old-password new-password Change old password to new-password in old format.\n");
1022
ping Check if mysqld is alive\n\
1023
processlist Show list of active threads in server\n\
1024
reload Reload grant tables\n\
1025
refresh Flush all tables and close and open logfiles\n\
1026
shutdown Take server down\n\
1027
status Gives a short status message from the server\n\
1028
start-slave Start slave\n\
1029
stop-slave Stop slave\n\
1030
variables Prints variables available\n\
1031
version Get version info from server");
1034
#include <help_end.h>
1036
static int drop_db(MYSQL *mysql, const char *db)
1038
char name_buff[FN_REFLEN+20], buf[10];
1041
puts("Dropping the database is potentially a very bad thing to do.");
1042
puts("Any data stored in the database will be destroyed.\n");
1043
printf("Do you really want to drop the '%s' database [y/N] ",db);
1045
VOID(fgets(buf,sizeof(buf)-1,stdin));
1046
if ((*buf != 'y') && (*buf != 'Y'))
1048
puts("\nOK, aborting database drop!");
1052
sprintf(name_buff,"drop database `%.*s`",FN_REFLEN,db);
1053
if (mysql_query(mysql,name_buff))
1055
my_printf_error(0, "DROP DATABASE %s failed;\nerror: '%s'", error_flags,
1056
db,mysql_error(mysql));
1059
printf("Database \"%s\" dropped\n",db);
1064
static void nice_time(ulong sec,char *buff)
1068
if (sec >= 3600L*24)
1072
buff=int10_to_str(tmp, buff, 10);
1073
buff=strmov(buff,tmp > 1 ? " days " : " day ");
1079
buff=int10_to_str(tmp, buff, 10);
1080
buff=strmov(buff,tmp > 1 ? " hours " : " hour ");
1086
buff=int10_to_str(tmp, buff, 10);
1087
buff=strmov(buff," min ");
1089
strmov(int10_to_str(sec, buff, 10)," sec");
1093
static void print_header(MYSQL_RES *result)
1098
mysql_field_seek(result,0);
1100
while ((field = mysql_fetch_field(result)))
1102
printf(" %-*s|",(int) field->max_length+1,field->name);
1109
static void print_top(MYSQL_RES *result)
1115
mysql_field_seek(result,0);
1116
while((field = mysql_fetch_field(result)))
1118
if ((length=(uint) strlen(field->name)) > field->max_length)
1119
field->max_length=length;
1121
length=field->max_length;
1122
for (i=length+2 ; i--> 0 ; )
1130
/* 3.rd argument, uint row, is not in use. Don't remove! */
1131
static void print_row(MYSQL_RES *result, MYSQL_ROW cur,
1132
uint row __attribute__((unused)))
1138
mysql_field_seek(result,0);
1139
for (i=0 ; i < mysql_num_fields(result); i++)
1141
field = mysql_fetch_field(result);
1142
length=field->max_length;
1143
printf(" %-*s|",length+1,cur[i] ? (char*) cur[i] : "");
1149
static void print_relative_row(MYSQL_RES *result, MYSQL_ROW cur, uint row)
1155
mysql_field_seek(result, 0);
1156
field = mysql_fetch_field(result);
1157
printf("| %-*s|", (int) field->max_length + 1, cur[0]);
1159
field = mysql_fetch_field(result);
1160
tmp = cur[1] ? strtoull(cur[1], NULL, 10) : (ulonglong) 0;
1161
printf(" %-*s|\n", (int) field->max_length + 1,
1162
llstr((tmp - last_values[row]), buff));
1163
last_values[row] = tmp;
1167
static void print_relative_row_vert(MYSQL_RES *result __attribute__((unused)),
1169
uint row __attribute__((unused)))
1178
tmp = cur[1] ? strtoull(cur[1], NULL, 10) : (ulonglong) 0;
1179
printf(" %-*s|", ex_val_max_len[row] + 1,
1180
llstr((tmp - last_values[row]), buff));
1182
/* Find the minimum row length needed to output the relative value */
1183
if ((length=(uint) strlen(buff) > ex_val_max_len[row]) && ex_status_printed)
1184
ex_val_max_len[row] = length;
1185
last_values[row] = tmp;
1189
static void store_values(MYSQL_RES *result)
1195
field = mysql_fetch_field(result);
1196
max_var_length = field->max_length;
1197
field = mysql_fetch_field(result);
1198
max_val_length = field->max_length;
1200
for (i = 0; (row = mysql_fetch_row(result)); i++)
1202
strmov(ex_var_names[i], row[0]);
1203
last_values[i]=strtoull(row[1],NULL,10);
1204
ex_val_max_len[i]=2; /* Default print width for values */
1211
static void print_relative_header()
1216
for (i = 0; i < ex_var_count; i++)
1217
printf(" %-*s|", ex_val_max_len[i] + 1, truncated_var_names[i]);
1222
static void print_relative_line()
1227
for (i = 0; i < ex_var_count; i++)
1230
for (j = 0; j < ex_val_max_len[i] + 2; j++)
1238
static void truncate_names()
1241
char *ptr,top_line[MAX_TRUNC_LENGTH+4+NAME_LEN+22+1],buff[22];
1245
ptr=strfill(ptr,max_var_length+2,'-');
1247
ptr=strfill(ptr,MAX_TRUNC_LENGTH+2,'-');
1249
ptr=strfill(ptr,max_val_length+2,'-');
1254
for (i = 0 ; i < ex_var_count; i++)
1257
printf("| %-*s|", max_var_length + 1, ex_var_names[i]);
1258
ptr = ex_var_names[i];
1259
/* Make sure no two same truncated names will become */
1260
for (j = 0; j < i; j++)
1261
if (*truncated_var_names[j] == *ptr)
1264
truncated_var_names[i][0]= *ptr; /* Copy first var char */
1265
int10_to_str(sfx, truncated_var_names[i]+1,10);
1266
printf(" %-*s|", MAX_TRUNC_LENGTH + 1, truncated_var_names[i]);
1267
printf(" %-*s|\n", max_val_length + 1, llstr(last_values[i],buff));
1274
static my_bool get_pidfile(MYSQL *mysql, char *pidfile)
1278
if (mysql_query(mysql, "SHOW VARIABLES LIKE 'pid_file'"))
1280
my_printf_error(0, "query failed; error: '%s'", error_flags,
1281
mysql_error(mysql));
1283
result = mysql_store_result(mysql);
1286
MYSQL_ROW row=mysql_fetch_row(result);
1288
strmov(pidfile, row[1]);
1289
mysql_free_result(result);
1290
return row == 0; /* Error if row = 0 */
1292
return 1; /* Error */
1296
Return 1 if pid file didn't disappear or change
1299
static my_bool wait_pidfile(char *pidfile, time_t last_modified,
1300
struct stat *pidfile_status)
1302
char buff[FN_REFLEN];
1305
DBUG_ENTER("wait_pidfile");
1307
system_filename(buff, pidfile);
1311
if ((fd= my_open(buff, O_RDONLY, MYF(0))) < 0)
1316
(void) my_close(fd,MYF(0));
1317
if (last_modified && !stat(pidfile, pidfile_status))
1319
if (last_modified != pidfile_status->st_mtime)
1321
/* File changed; Let's assume that mysqld did restart */
1323
printf("pid file '%s' changed while waiting for it to disappear!\nmysqld did probably restart\n",
1329
if (count++ == opt_shutdown_timeout)
1332
} while (!interrupted);
1336
DBUG_PRINT("warning",("Pid file didn't disappear"));
1338
"Warning; Aborted waiting on pid file: '%s' after %d seconds\n",