1
/* Copyright (C) 2000-2006 MySQL AB
1
/* Copyright (C) 2008 Drizzle Open Source Project
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* maintaince of mysql databases */
16
/* maintaince of drizzle databases */
18
18
#include "client_priv.h"
19
19
#include <signal.h>
26
26
char *host= NULL, *user= NULL, *opt_password= NULL;
27
27
static bool interrupted= false, opt_verbose= false,tty_password= false;
28
static uint8_t opt_protocol= MYSQL_PROTOCOL_TCP;
28
static uint8_t opt_protocol= DRIZZLE_PROTOCOL_TCP;
29
29
static uint32_t tcp_port= 0, option_wait= 0, option_silent= 0;
30
30
static uint32_t my_end_arg;
31
31
static uint32_t opt_connect_timeout, opt_shutdown_timeout;
39
39
extern "C" sig_handler endprog(int signal_number);
40
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);
43
static bool sql_connect(MYSQL *mysql, uint wait);
42
static int execute_commands(DRIZZLE *drizzle,int argc, char **argv);
43
static bool sql_connect(DRIZZLE *drizzle, uint wait);
46
46
The order of commands must be the same as command_names,
103
static const char *load_default_groups[]= { "mysqladmin","client",0 };
103
static const char *load_default_groups[]= { "drizzleadmin","client",0 };
106
106
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
156
156
int main(int argc,char *argv[])
158
158
int error= 0, ho_error;
160
160
char **commands, **save_argv;
162
162
MY_INIT(argv[0]);
163
drizzle_create(&drizzle);
164
164
load_defaults("my",load_default_groups,&argc,&argv);
165
165
save_argv = argv; /* Save for free_defaults */
166
166
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
185
185
if (opt_connect_timeout)
187
187
uint tmp=opt_connect_timeout;
188
mysql_options(&mysql,MYSQL_OPT_CONNECT_TIMEOUT, (char*) &tmp);
188
drizzle_options(&drizzle,DRIZZLE_OPT_CONNECT_TIMEOUT, (char*) &tmp);
190
/* force mysqladmin to use TCP */
191
mysql_options(&mysql, MYSQL_OPT_PROTOCOL, (char*)&opt_protocol);
190
/* force drizzleadmin to use TCP */
191
drizzle_options(&drizzle, DRIZZLE_OPT_PROTOCOL, (char*)&opt_protocol);
193
193
error_flags= (myf)0;
195
if (sql_connect(&mysql, option_wait))
195
if (sql_connect(&drizzle, option_wait))
197
unsigned int err= mysql_errno(&mysql);
197
unsigned int err= drizzle_errno(&drizzle);
198
198
if (err >= CR_MIN_ERROR && err <= CR_MAX_ERROR)
215
error=execute_commands(&mysql,argc,commands);
215
error=execute_commands(&drizzle,argc,commands);
216
drizzle_close(&drizzle);
218
218
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
219
219
my_free(user,MYF(MY_ALLOW_ZERO_PTR));
230
static bool sql_connect(MYSQL *mysql, uint wait)
230
static bool sql_connect(DRIZZLE *drizzle, uint wait)
236
if (mysql_real_connect(mysql,host,user,opt_password,NullS,tcp_port,NULL,0))
236
if (drizzle_connect(drizzle,host,user,opt_password,NullS,tcp_port,NULL,0))
238
drizzle->reconnect= 1;
241
241
fputs("\n",stderr);
252
252
host= (char*) LOCAL_HOST;
254
254
my_printf_error(0,"connect to server at '%s' failed\nerror: '%s'",
255
error_flags, host, mysql_error(mysql));
255
error_flags, host, drizzle_error(drizzle));
257
if (mysql_errno(mysql) == CR_CONN_HOST_ERROR ||
258
mysql_errno(mysql) == CR_UNKNOWN_HOST)
257
if (drizzle_errno(drizzle) == CR_CONN_HOST_ERROR ||
258
drizzle_errno(drizzle) == CR_UNKNOWN_HOST)
260
260
fprintf(stderr,"Check that drizzled is running on %s",host);
261
261
fprintf(stderr," and that the port is %d.\n",
262
tcp_port ? tcp_port: mysql_port);
262
tcp_port ? tcp_port: drizzle_port);
263
263
fprintf(stderr,"You can check this by doing 'telnet %s %d'\n",
264
host, tcp_port ? tcp_port: mysql_port);
264
host, tcp_port ? tcp_port: drizzle_port);
269
269
if (wait != (uint) ~0)
270
270
wait--; /* One less retry */
271
if ((mysql_errno(mysql) != CR_CONN_HOST_ERROR) &&
272
(mysql_errno(mysql) != CR_CONNECTION_ERROR))
271
if ((drizzle_errno(drizzle) != CR_CONN_HOST_ERROR) &&
272
(drizzle_errno(drizzle) != CR_CONNECTION_ERROR))
274
fprintf(stderr,"Got error: %s\n", mysql_error(mysql));
274
fprintf(stderr,"Got error: %s\n", drizzle_error(drizzle));
276
276
else if (!option_silent)
297
297
-1 on retryable error
300
static int execute_commands(MYSQL *mysql,int argc, char **argv)
300
static int execute_commands(DRIZZLE *drizzle,int argc, char **argv)
304
MySQL documentation relies on the fact that mysqladmin will
304
DRIZZLE documentation relies on the fact that drizzleadmin will
305
305
execute commands in the order specified.
306
306
If this behaviour is ever changed, Docs should be notified.
314
314
printf("shutting down drizzled...\n");
316
if (mysql_shutdown(mysql, SHUTDOWN_DEFAULT))
316
if (drizzle_shutdown(drizzle, SHUTDOWN_DEFAULT))
318
318
my_printf_error(0, "shutdown failed; error: '%s'", error_flags,
319
drizzle_error(drizzle));
322
mysql_close(mysql); /* Close connection to avoid error messages */
322
drizzle_close(drizzle); /* Close connection to avoid error messages */
325
325
printf("done\n");
331
mysql->reconnect=0; /* We want to know of reconnects */
332
if (!mysql_ping(mysql))
331
drizzle->reconnect=0; /* We want to know of reconnects */
332
if (!drizzle_ping(drizzle))
334
334
if (option_silent < 2)
335
335
puts("drizzled is alive");
339
if (mysql_errno(mysql) == CR_SERVER_GONE_ERROR)
339
if (drizzle_errno(drizzle) == CR_SERVER_GONE_ERROR)
342
if (!mysql_ping(mysql))
341
drizzle->reconnect=1;
342
if (!drizzle_ping(drizzle))
343
343
puts("connection was down, but drizzled is now alive");
347
347
my_printf_error(0,"drizzled doesn't answer to ping, error: '%s'",
348
error_flags, mysql_error(mysql));
348
error_flags, drizzle_error(drizzle));
352
mysql->reconnect=1; /* Automatic reconnect is default */
352
drizzle->reconnect=1; /* Automatic reconnect is default */
369
369
static void usage(void)
372
puts("Copyright (C) 2000-2006 MySQL AB");
372
puts("Copyright (C) 2000-2006 DRIZZLE AB");
373
373
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");
374
374
puts("Administration program for the drizzled daemon.");
375
375
printf("Usage: %s [OPTIONS] command command....\n", my_progname);