MySQL  8.0.17
Source Code Documentation
mysqladmin.cc File Reference
#include <fcntl.h>
#include <mysql.h>
#include <mysqld_error.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <string>
#include "client/client_priv.h"
#include "m_ctype.h"
#include "my_alloc.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_default.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_thread.h"
#include "mysql/service_mysql_alloc.h"
#include "print_version.h"
#include "sql_common.h"
#include "typelib.h"
#include "welcome_copyright_notice.h"
#include "sslopt-vars.h"
#include "caching_sha2_passwordopt-vars.h"
#include "sslopt-longopts.h"
#include "caching_sha2_passwordopt-longopts.h"
#include "sslopt-case.h"

Macros

#define MAX_MYSQL_VAR   512
 
#define SHUTDOWN_DEF_TIMEOUT   3600 /* Wait for shutdown */
 
#define MAX_TRUNC_LENGTH   3
 

Enumerations

enum  commands {
  MY_CONFIG_SET, MY_CONFIG_REMOVE, MY_CONFIG_PRINT, MY_CONFIG_RESET,
  MY_CONFIG_HELP, 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
}
 

Functions

static void usage (void)
 
bool get_one_option (int optid, const struct my_option *opt, char *argument)
 
static bool sql_connect (MYSQL *mysql, uint wait)
 connect to server, optionally waiting for same to come up More...
 
static int execute_commands (MYSQL *mysql, int argc, char **argv)
 Execute all commands. More...
 
static char ** mask_password (int argc, char ***argv)
 Masking the password if it is passed as command line argument. More...
 
static int drop_db (MYSQL *mysql, const char *db)
 
void endprog (int signal_number)
 
static void nice_time (ulong sec, char *buff)
 
static void print_header (MYSQL_RES *result)
 
static void print_top (MYSQL_RES *result)
 
static void print_row (MYSQL_RES *result, MYSQL_ROW cur, uint row)
 
static void print_relative_row (MYSQL_RES *result, MYSQL_ROW cur, uint row)
 
static void print_relative_row_vert (MYSQL_RES *result, MYSQL_ROW cur, uint row)
 
static void print_relative_header ()
 
static void print_relative_line ()
 
static void truncate_names ()
 
static bool get_pidfile (MYSQL *mysql, char *pidfile)
 
static bool wait_pidfile (char *pidfile, time_t last_modified, struct stat *pidfile_status)
 
static void store_values (MYSQL_RES *result)
 
static void print_warnings (MYSQL *mysql)
 
int main (int argc, char *argv[])
 

Variables

const char * host = nullptr
 
char * user = 0
 
char * opt_password = 0
 
const char * default_charset = MYSQL_AUTODETECT_CHARSET_NAME
 
char truncated_var_names [MAX_MYSQL_VAR][MAX_TRUNC_LENGTH]
 
char ex_var_names [MAX_MYSQL_VAR][FN_REFLEN]
 
ulonglong last_values [MAX_MYSQL_VAR]
 
static int interval = 0
 
static bool option_force = 0
 
static bool interrupted = 0
 
static bool new_line = 0
 
static bool opt_compress = 0
 
static bool opt_relative = 0
 
static bool opt_verbose = 0
 
static bool opt_vertical = 0
 
static bool tty_password = 0
 
static bool opt_nobeep
 
static bool debug_info_flag = 0
 
static bool debug_check_flag = 0
 
static uint tcp_port = 0
 
static uint option_wait = 0
 
static uint option_silent = 0
 
static uint nr_iterations
 
static uint opt_count_iterations = 0
 
static uint my_end_arg
 
static char * opt_bind_addr = NULL
 
static ulong opt_connect_timeout
 
static ulong opt_shutdown_timeout
 
static char * unix_port = 0
 
static char * opt_plugin_dir = 0
 
static char * opt_default_auth = 0
 
static uint opt_enable_cleartext_plugin = 0
 
static bool using_opt_enable_cleartext_plugin = 0
 
static bool opt_show_warnings = 0
 
static uint opt_protocol = 0
 
static myf error_flags
 
static uint ex_val_max_len [MAX_MYSQL_VAR]
 
static bool ex_status_printed = 0
 
static uint ex_var_count
 
static uint max_var_length
 
static uint max_val_length
 
static const char * command_names []
 
static TYPELIB command_typelib
 
static struct my_option my_long_options []
 
static const char * load_default_groups [] = {"mysqladmin", "client", 0}
 

Macro Definition Documentation

◆ MAX_MYSQL_VAR

#define MAX_MYSQL_VAR   512

◆ MAX_TRUNC_LENGTH

#define MAX_TRUNC_LENGTH   3

◆ SHUTDOWN_DEF_TIMEOUT

#define SHUTDOWN_DEF_TIMEOUT   3600 /* Wait for shutdown */

Enumeration Type Documentation

◆ commands

enum commands
Enumerator
MY_CONFIG_SET 
MY_CONFIG_REMOVE 
MY_CONFIG_PRINT 
MY_CONFIG_RESET 
MY_CONFIG_HELP 
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 

Function Documentation

◆ drop_db()

static int drop_db ( MYSQL mysql,
const char *  db 
)
static

◆ endprog()

static void endprog ( int  signal_number)

◆ execute_commands()

static int execute_commands ( MYSQL mysql,
int  argc,
char **  argv 
)
static

Execute all commands.

We try to execute all commands we were given, in the order given, but return with non-zero as soon as we encounter trouble. By that token, individual commands can be considered a conjunction with boolean short-cut.

Returns
success?
Return values
0Yes! ALL commands worked!
1No, one failed and will never work (malformed): fatal error!
-1No, one failed on the server, may work next time!

◆ get_one_option()

bool get_one_option ( int  optid,
const struct my_option opt,
char *  argument 
)

◆ get_pidfile()

static bool get_pidfile ( MYSQL mysql,
char *  pidfile 
)
static

◆ main()

int main ( int  argc,
char *  argv[] 
)

◆ mask_password()

static char ** mask_password ( int  argc,
char ***  argv 
)
static

Masking the password if it is passed as command line argument.

It works in Linux and changes cmdline in ps and /proc/pid/cmdline, but it won't work for history file of shell. The command line arguments are copied to another array and the password in the argv is masked. This function is called just after "handle_options" because in "handle_options", the agrv pointers are altered which makes freeing of dynamically allocated memory difficult. The password masking is done before all other operations in order to minimise the time frame of password visibility via cmdline.

Parameters
argccommand line options (count)
argvcommand line options (values)
Returns
temp_argv copy of argv

◆ nice_time()

static void nice_time ( ulong  sec,
char *  buff 
)
static

◆ print_header()

static void print_header ( MYSQL_RES result)
static

◆ print_relative_header()

static void print_relative_header ( )
static

◆ print_relative_line()

static void print_relative_line ( )
static

◆ print_relative_row()

static void print_relative_row ( MYSQL_RES result,
MYSQL_ROW  cur,
uint  row 
)
static

◆ print_relative_row_vert()

static void print_relative_row_vert ( MYSQL_RES result,
MYSQL_ROW  cur,
uint  row 
)
static

◆ print_row()

static void print_row ( MYSQL_RES result,
MYSQL_ROW  cur,
uint  row 
)
static

◆ print_top()

static void print_top ( MYSQL_RES result)
static

◆ print_warnings()

static void print_warnings ( MYSQL mysql)
static

◆ sql_connect()

static bool sql_connect ( MYSQL mysql,
uint  wait 
)
static

connect to server, optionally waiting for same to come up

Parameters
mysqlconnection struct
waitwait for server to come up? (0: no, ~0: forever, n: cycles)
Returns
Operation result
Return values
0success
1failure

◆ store_values()

static void store_values ( MYSQL_RES result)
static

◆ truncate_names()

static void truncate_names ( )
static

◆ usage()

static void usage ( void  )
static

◆ wait_pidfile()

static bool wait_pidfile ( char *  pidfile,
time_t  last_modified,
struct stat *  pidfile_status 
)
static

Variable Documentation

◆ command_names

const char* command_names[]
static
Initial value:
= {"create",
"drop",
"shutdown",
"reload",
"refresh",
"version",
"processlist",
"status",
"kill",
"debug",
"variables",
"flush-logs",
"flush-hosts",
"flush-tables",
"password",
"ping",
"extended-status",
"flush-status",
"flush-privileges",
"start-slave",
"stop-slave",
"flush-threads",
#define NullS
Definition of the null string (a null pointer of type char *), used in some of our string handling co...
Definition: m_string.h:49

◆ command_typelib

TYPELIB command_typelib
static
Initial value:
= {array_elements(command_names) - 1, "commands",
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
static const char * command_names[]
Definition: mysqladmin.cc:150
constexpr size_t array_elements(T(&)[N]) noexcept
Definition: my_macros.h:77

◆ debug_check_flag

bool debug_check_flag = 0
static

◆ debug_info_flag

bool debug_info_flag = 0
static

◆ default_charset

const char* default_charset = MYSQL_AUTODETECT_CHARSET_NAME

◆ error_flags

myf error_flags
static

◆ ex_status_printed

bool ex_status_printed = 0
static

◆ ex_val_max_len

uint ex_val_max_len[MAX_MYSQL_VAR]
static

◆ ex_var_count

uint ex_var_count
static

◆ ex_var_names

char ex_var_names[MAX_MYSQL_VAR][FN_REFLEN]

◆ host

const char* host = nullptr

◆ interrupted

bool interrupted = 0
static

◆ interval

int interval = 0
static

◆ last_values

ulonglong last_values[MAX_MYSQL_VAR]

◆ load_default_groups

const char* load_default_groups[] = {"mysqladmin", "client", 0}
static

◆ max_val_length

uint max_val_length
static

◆ max_var_length

uint max_var_length
static

◆ my_end_arg

uint my_end_arg
static

◆ my_long_options

struct my_option my_long_options[]
static

◆ new_line

bool new_line = 0
static

◆ nr_iterations

uint nr_iterations
static

◆ opt_bind_addr

char* opt_bind_addr = NULL
static

◆ opt_compress

bool opt_compress = 0
static

◆ opt_connect_timeout

ulong opt_connect_timeout
static

◆ opt_count_iterations

uint opt_count_iterations = 0
static

◆ opt_default_auth

char * opt_default_auth = 0
static

◆ opt_enable_cleartext_plugin

uint opt_enable_cleartext_plugin = 0
static

◆ opt_nobeep

bool opt_nobeep
static

◆ opt_password

char * opt_password = 0

◆ opt_plugin_dir

char* opt_plugin_dir = 0
static

◆ opt_protocol

uint opt_protocol = 0
static

◆ opt_relative

bool opt_relative = 0
static

◆ opt_show_warnings

bool opt_show_warnings = 0
static

◆ opt_shutdown_timeout

ulong opt_shutdown_timeout
static

◆ opt_verbose

bool opt_verbose = 0
static

◆ opt_vertical

bool opt_vertical = 0
static

◆ option_force

bool option_force = 0
static

◆ option_silent

uint option_silent = 0
static

◆ option_wait

uint option_wait = 0
static

◆ tcp_port

uint tcp_port = 0
static

◆ truncated_var_names

char truncated_var_names[MAX_MYSQL_VAR][MAX_TRUNC_LENGTH]

◆ tty_password

bool tty_password = 0
static

◆ unix_port

char* unix_port = 0
static

◆ user

char* user = 0

◆ using_opt_enable_cleartext_plugin

bool using_opt_enable_cleartext_plugin = 0
static