summaryrefslogtreecommitdiff
path: root/client/mysqladmin.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/mysqladmin.c')
-rw-r--r--client/mysqladmin.c148
1 files changed, 104 insertions, 44 deletions
diff --git a/client/mysqladmin.c b/client/mysqladmin.c
index 3bc11ec0fb0..df3e8dfed62 100644
--- a/client/mysqladmin.c
+++ b/client/mysqladmin.c
@@ -23,6 +23,7 @@
#include <my_pthread.h> /* because of signal() */
#endif
#include <sys/stat.h>
+#include <mysql.h>
#define ADMIN_VERSION "8.40"
#define MAX_MYSQL_VAR 256
@@ -42,6 +43,11 @@ static uint tcp_port = 0, option_wait = 0, option_silent=0, nr_iterations,
static ulong opt_connect_timeout, opt_shutdown_timeout;
static my_string unix_port=0;
+#ifdef HAVE_SMEM
+static char *shared_memory_base_name=0;
+#endif
+static uint opt_protocol=0;
+
/*
When using extended-status relatively, ex_val_max_len is the estimated
maximum length for any relative value printed by extended-status. The
@@ -78,16 +84,16 @@ static void store_values(MYSQL_RES *result);
The order of commands must be the same as command_names,
except ADMIN_ERROR
*/
-enum commands {
- ADMIN_ERROR,
+enum commands {
+ ADMIN_ERROR,
ADMIN_CREATE, ADMIN_DROP, ADMIN_SHUTDOWN,
- ADMIN_RELOAD, ADMIN_REFRESH, ADMIN_VER,
- ADMIN_PROCESSLIST, ADMIN_STATUS, ADMIN_KILL,
- ADMIN_DEBUG, ADMIN_VARIABLES, ADMIN_FLUSH_LOGS,
- ADMIN_FLUSH_HOSTS, ADMIN_FLUSH_TABLES, ADMIN_PASSWORD,
- ADMIN_PING, ADMIN_EXTENDED_STATUS, ADMIN_FLUSH_STATUS,
- ADMIN_FLUSH_PRIVILEGES, ADMIN_START_SLAVE, ADMIN_STOP_SLAVE,
- ADMIN_FLUSH_THREADS
+ ADMIN_RELOAD, ADMIN_REFRESH, ADMIN_VER,
+ ADMIN_PROCESSLIST, ADMIN_STATUS, ADMIN_KILL,
+ ADMIN_DEBUG, ADMIN_VARIABLES, ADMIN_FLUSH_LOGS,
+ ADMIN_FLUSH_HOSTS, ADMIN_FLUSH_TABLES, ADMIN_PASSWORD,
+ ADMIN_PING, ADMIN_EXTENDED_STATUS, ADMIN_FLUSH_STATUS,
+ ADMIN_FLUSH_PRIVILEGES, ADMIN_START_SLAVE, ADMIN_STOP_SLAVE,
+ ADMIN_FLUSH_THREADS, ADMIN_OLD_PASSWORD
};
static const char *command_names[]= {
"create", "drop", "shutdown",
@@ -96,8 +102,8 @@ static const char *command_names[]= {
"debug", "variables", "flush-logs",
"flush-hosts", "flush-tables", "password",
"ping", "extended-status", "flush-status",
- "flush-privileges", "start-slave", "stop-slave",
- "flush-threads",
+ "flush-privileges", "start-slave", "stop-slave",
+ "flush-threads","old-password",
NullS
};
@@ -107,16 +113,16 @@ static TYPELIB command_typelib=
static struct my_option my_long_options[] =
{
{"count", 'c',
- "Number of iterations to make. This works with -i (--sleep) only",
+ "Number of iterations to make. This works with -i (--sleep) only.",
(gptr*) &nr_iterations, (gptr*) &nr_iterations, 0, GET_UINT,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'",
+ {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.",
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"force", 'f',
"Don't ask for confirmation on drop database; with multiple commands, continue even if an error occurs.",
(gptr*) &option_force, (gptr*) &option_force, 0, GET_BOOL, NO_ARG, 0, 0,
0, 0, 0, 0},
- {"compress", 'C', "Use compression in server/client protocol",
+ {"compress", 'C', "Use compression in server/client protocol.",
(gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
{"character-sets-dir", OPT_CHARSETS_DIR,
@@ -124,7 +130,7 @@ static struct my_option my_long_options[] =
(gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
- {"host", 'h', "Connect to host", (gptr*) &host, (gptr*) &host, 0, GET_STR,
+ {"host", 'h', "Connect to host.", (gptr*) &host, (gptr*) &host, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p',
"Password to use when connecting to server. If password is not given it's asked from the tty.",
@@ -135,6 +141,8 @@ static struct my_option my_long_options[] =
#endif
{"port", 'P', "Port number to use for connection.", (gptr*) &tcp_port,
(gptr*) &tcp_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0, 0},
+ {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"relative", 'r',
"Show difference between current and previous values when used with -i. Currently works only with extended-status.",
(gptr*) &opt_relative, (gptr*) &opt_relative, 0, GET_BOOL, NO_ARG, 0, 0, 0,
@@ -142,7 +150,12 @@ static struct my_option my_long_options[] =
{"set-variable", 'O',
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- {"silent", 's', "Silently exit if one can't connect to server",
+#ifdef HAVE_SMEM
+ {"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
+ "Base name of shared memory.", (gptr*) &shared_memory_base_name, (gptr*) &shared_memory_base_name,
+ 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#endif
+ {"silent", 's', "Silently exit if one can't connect to server.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"socket", 'S', "Socket file to use for connection.",
(gptr*) &unix_port, (gptr*) &unix_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
@@ -157,13 +170,13 @@ static struct my_option my_long_options[] =
#endif
{"verbose", 'v', "Write more information.", (gptr*) &opt_verbose,
(gptr*) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
- {"version", 'V', "Output version information and exit", 0, 0, 0, GET_NO_ARG,
+ {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
- {"vertical", 'E',
+ {"vertical", 'E',
"Print output vertically. Is similar to --relative, but prints output vertically.",
(gptr*) &opt_vertical, (gptr*) &opt_vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
- {"wait", 'w', "Wait and retry if connection is down", 0, 0, 0, GET_UINT,
+ {"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_UINT,
OPT_ARG, 0, 0, 0, 0, 0, 0},
{"connect_timeout", OPT_CONNECT_TIMEOUT, "", (gptr*) &opt_connect_timeout,
(gptr*) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 3600*12, 0,
@@ -205,7 +218,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break;
case 'W':
#ifdef __WIN__
- unix_port=MYSQL_NAMEDPIPE;
+ opt_protocol = MYSQL_PROTOCOL_PIPE;
#endif
break;
case '#':
@@ -234,6 +247,15 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
charsets_dir = argument;
#endif
break;
+ case OPT_MYSQL_PROTOCOL:
+ {
+ if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0)
+ {
+ fprintf(stderr, "Unknown option to protocol: %s\n", argument);
+ exit(1);
+ }
+ break;
+ }
}
if (error)
{
@@ -284,6 +306,12 @@ int main(int argc,char *argv[])
mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
opt_ssl_capath, opt_ssl_cipher);
#endif
+ if (opt_protocol)
+ mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
+#ifdef HAVE_SMEM
+ if (shared_memory_base_name)
+ mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
+#endif
if (sql_connect(&mysql, option_wait))
error = 1;
else
@@ -326,6 +354,9 @@ int main(int argc,char *argv[])
}
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
my_free(user,MYF(MY_ALLOW_ZERO_PTR));
+#ifdef HAVE_SMEM
+ my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
+#endif
free_defaults(save_argv);
my_end(0);
exit(error ? 1 : 0);
@@ -386,7 +417,7 @@ static my_bool sql_connect(MYSQL *mysql, uint wait)
wait--; /* One less retry */
if ((mysql_errno(mysql) != CR_CONN_HOST_ERROR) &&
(mysql_errno(mysql) != CR_CONNECTION_ERROR))
- {
+ {
fprintf(stderr,"Got error: %s\n", mysql_error(mysql));
if (!option_force)
return 1;
@@ -401,7 +432,7 @@ static my_bool sql_connect(MYSQL *mysql, uint wait)
}
else
{
- putc('.',stderr);
+ putc('.',stderr);
(void) fflush(stderr);
}
}
@@ -420,7 +451,6 @@ static my_bool sql_connect(MYSQL *mysql, uint wait)
static int execute_commands(MYSQL *mysql,int argc, char **argv)
{
const char *status;
-
/*
MySQL documentation relies on the fact that mysqladmin will
execute commands in the order specified, e.g.
@@ -429,6 +459,8 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
If this behaviour is ever changed, Docs should be notified.
*/
+ struct rand_struct rand_st;
+
for (; argc > 0 ; argv++,argc--)
{
switch (find_type(argv[0],&command_typelib,2)) {
@@ -477,7 +509,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
!stat(pidfile, &pidfile_status))
last_modified= pidfile_status.st_mtime;
- if (mysql_shutdown(mysql))
+ if (mysql_shutdown(mysql, SHUTDOWN_DEFAULT))
{
my_printf_error(0,"shutdown failed; error: '%s'",MYF(ME_BELL),
mysql_error(mysql));
@@ -497,7 +529,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
}
case ADMIN_FLUSH_PRIVILEGES:
case ADMIN_RELOAD:
- if (mysql_refresh(mysql,REFRESH_GRANT) < 0)
+ if (mysql_query(mysql,"flush privileges"))
{
my_printf_error(0,"reload failed; error: '%s'",MYF(ME_BELL),
mysql_error(mysql));
@@ -508,7 +540,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
if (mysql_refresh(mysql,
(uint) ~(REFRESH_GRANT | REFRESH_STATUS |
REFRESH_READ_LOCK | REFRESH_SLAVE |
- REFRESH_MASTER)) < 0)
+ REFRESH_MASTER)))
{
my_printf_error(0,"refresh failed; error: '%s'",MYF(ME_BELL),
mysql_error(mysql));
@@ -516,7 +548,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
}
break;
case ADMIN_FLUSH_THREADS:
- if (mysql_refresh(mysql,(uint) REFRESH_THREADS) < 0)
+ if (mysql_refresh(mysql,(uint) REFRESH_THREADS))
{
my_printf_error(0,"refresh failed; error: '%s'",MYF(ME_BELL),
mysql_error(mysql));
@@ -639,7 +671,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
MYSQL_RES *res;
MYSQL_ROW row;
uint rownr = 0;
- void (*func) (MYSQL_RES*, MYSQL_ROW, uint);
+ void (*func) (MYSQL_RES*, MYSQL_ROW, uint);
new_line = 1;
if (mysql_query(mysql, "show status") ||
@@ -703,7 +735,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
}
case ADMIN_FLUSH_HOSTS:
{
- if (mysql_refresh(mysql,REFRESH_HOSTS))
+ if (mysql_query(mysql,"flush hosts"))
{
my_printf_error(0,"refresh failed; error: '%s'",MYF(ME_BELL),
mysql_error(mysql));
@@ -713,7 +745,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
}
case ADMIN_FLUSH_TABLES:
{
- if (mysql_refresh(mysql,REFRESH_TABLES))
+ if (mysql_query(mysql,"flush tables"))
{
my_printf_error(0,"refresh failed; error: '%s'",MYF(ME_BELL),
mysql_error(mysql));
@@ -723,7 +755,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
}
case ADMIN_FLUSH_STATUS:
{
- if (mysql_refresh(mysql,REFRESH_STATUS))
+ if (mysql_query(mysql,"flush status"))
{
my_printf_error(0,"refresh failed; error: '%s'",MYF(ME_BELL),
mysql_error(mysql));
@@ -731,9 +763,14 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
}
break;
}
+ case ADMIN_OLD_PASSWORD:
case ADMIN_PASSWORD:
{
- char buff[128],crypted_pw[33];
+ char buff[128],crypted_pw[64];
+ time_t start_time;
+ /* Do initialization the same way as we do in mysqld */
+ start_time=time((time_t*) 0);
+ randominit(&rand_st,(ulong) start_time,(ulong) start_time/2);
if (argc < 2)
{
@@ -741,7 +778,12 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
return 1;
}
if (argv[1][0])
- make_scrambled_password(crypted_pw,argv[1]);
+ {
+ if (find_type(argv[0], &command_typelib, 2) == ADMIN_OLD_PASSWORD)
+ make_scrambled_password_323(crypted_pw, argv[1]);
+ else
+ make_scrambled_password(crypted_pw, argv[1]);
+ }
else
crypted_pw[0]=0; /* No password */
sprintf(buff,"set password='%s',sql_log_off=0",crypted_pw);
@@ -754,16 +796,33 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
}
if (mysql_query(mysql,buff))
{
- my_printf_error(0,"unable to change password; error: '%s'",
- MYF(ME_BELL),mysql_error(mysql));
- return -1;
+ if (mysql_errno(mysql)!=1290)
+ {
+ my_printf_error(0,"unable to change password; error: '%s'",
+ MYF(ME_BELL),mysql_error(mysql));
+ return -1;
+ }
+ else
+ {
+ /*
+ We don't try to execute 'update mysql.user set..'
+ because we can't perfectly find out the host
+ */
+ my_printf_error(0,"\n"
+ "You cannot use 'password' command as mysqld runs\n"
+ " with grant tables disabled (was started with"
+ " --skip-grant-tables).\n"
+ "Use: \"mysqladmin flush-privileges password '*'\""
+ " instead", MYF(ME_BELL));
+ return -1;
+ }
}
argc--; argv++;
break;
}
case ADMIN_START_SLAVE:
- if (mysql_query(mysql, "SLAVE START"))
+ if (mysql_query(mysql, "START SLAVE"))
{
my_printf_error(0, "Error starting slave: %s", MYF(ME_BELL),
mysql_error(mysql));
@@ -773,7 +832,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
puts("Slave started");
break;
case ADMIN_STOP_SLAVE:
- if (mysql_query(mysql, "SLAVE STOP"))
+ if (mysql_query(mysql, "STOP SLAVE"))
{
my_printf_error(0, "Error stopping slave: %s", MYF(ME_BELL),
mysql_error(mysql));
@@ -848,7 +907,8 @@ static void usage(void)
kill id,id,... Kill mysql threads");
#if MYSQL_VERSION_ID >= 32200
puts("\
- password new-password Change old password to new-password");
+ password new-password Change old password to new-password, MySQL 4.1 hashing.\n\
+ old-password new-password Change old password to new-password in old format.\n");
#endif
puts("\
ping Check if mysqld is alive\n\
@@ -901,24 +961,24 @@ static void nice_time(ulong sec,char *buff)
{
tmp=sec/(3600L*24);
sec-=3600L*24*tmp;
- buff=int2str(tmp,buff,10);
+ buff=int10_to_str(tmp, buff, 10);
buff=strmov(buff,tmp > 1 ? " days " : " day ");
}
if (sec >= 3600L)
{
tmp=sec/3600L;
sec-=3600L*tmp;
- buff=int2str(tmp,buff,10);
+ buff=int10_to_str(tmp, buff, 10);
buff=strmov(buff,tmp > 1 ? " hours " : " hour ");
}
if (sec >= 60)
{
tmp=sec/60;
sec-=60*tmp;
- buff=int2str(tmp,buff,10);
+ buff=int10_to_str(tmp, buff, 10);
buff=strmov(buff," min ");
}
- strmov(int2str(sec,buff,10)," sec");
+ strmov(int10_to_str(sec, buff, 10)," sec");
}
@@ -1008,7 +1068,7 @@ static void print_relative_row_vert(MYSQL_RES *result __attribute__((unused)),
putchar('|');
tmp = cur[1] ? strtoull(cur[1], NULL, 10) : (ulonglong) 0;
- printf(" %-*s|", ex_val_max_len[row] + 1,
+ printf(" %-*s|", ex_val_max_len[row] + 1,
llstr((tmp - last_values[row]), buff));
/* Find the minimum row length needed to output the relative value */