MySQL 8.4.3
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/include/client_priv.h"
#include "compression.h"
#include "m_string.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 "mysql/strings/int2str.h"
#include "mysql/strings/m_ctype.h"
#include "nulls.h"
#include "print_version.h"
#include "sql_common.h"
#include "str2int.h"
#include "strxmov.h"
#include "typelib.h"
#include "welcome_copyright_notice.h"
#include "client/include/sslopt-vars.h"
#include "client/include/caching_sha2_passwordopt-vars.h"
#include "client/include/multi_factor_passwordopt-vars.h"
#include "client/include/multi_factor_passwordopt-longopts.h"
#include "client/include/sslopt-longopts.h"
#include "client/include/caching_sha2_passwordopt-longopts.h"
#include "client/include/sslopt-case.h"

Macros

#define MAX_MYSQL_VAR   8192
 
#define SHUTDOWN_DEF_TIMEOUT   3600 /* Wait for shutdown */
 
#define MAX_TRUNC_LENGTH   3
 
#define FIRST_SOURCE_COMMAND_VERSION   80200
 

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_REPLICA , ADMIN_STOP_REPLICA , ADMIN_START_SLAVE ,
  ADMIN_STOP_SLAVE
}
 

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 = nullptr
 
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 = false
 
static bool interrupted = false
 
static bool new_line = false
 
static bool opt_compress = false
 
static bool opt_relative = false
 
static bool opt_verbose = false
 
static bool opt_vertical = false
 
static bool opt_nobeep
 
static bool debug_info_flag = false
 
static bool debug_check_flag = false
 
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 = 0
 
static char * opt_bind_addr = nullptr
 
static ulong opt_connect_timeout
 
static ulong opt_shutdown_timeout
 
static char * unix_port = nullptr
 
static char * opt_plugin_dir = nullptr
 
static char * opt_default_auth = nullptr
 
static uint opt_enable_cleartext_plugin = 0
 
static bool using_opt_enable_cleartext_plugin = false
 
static bool opt_show_warnings = false
 
static uint opt_zstd_compress_level = default_zstd_compression_level
 
static char * opt_compress_algorithm = nullptr
 
static uint opt_protocol = 0
 
static myf error_flags
 
static uint ex_val_max_len [MAX_MYSQL_VAR]
 
static bool ex_status_printed = false
 
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", nullptr}
 

Macro Definition Documentation

◆ FIRST_SOURCE_COMMAND_VERSION

#define FIRST_SOURCE_COMMAND_VERSION   80200

◆ MAX_MYSQL_VAR

#define MAX_MYSQL_VAR   8192

◆ 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_REPLICA 
ADMIN_STOP_REPLICA 
ADMIN_START_SLAVE 
ADMIN_STOP_SLAVE 

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-replica",
"stop-replica",
"start-slave",
"stop-slave",
#define NullS
Definition of the null string (a null pointer of type char *), used in some of our string handling co...
Definition: nulls.h:33

◆ command_typelib

TYPELIB command_typelib
static
Initial value:
= {array_elements(command_names) - 1, "commands",
command_names, nullptr}
static const char * command_names[]
Definition: mysqladmin.cc:161
#define array_elements(A)
Definition: validate_password_imp.cc:48

◆ debug_check_flag

bool debug_check_flag = false
static

◆ debug_info_flag

bool debug_info_flag = false
static

◆ default_charset

const char* default_charset = MYSQL_AUTODETECT_CHARSET_NAME

◆ error_flags

myf error_flags
static

◆ ex_status_printed

bool ex_status_printed = false
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 = false
static

◆ interval

int interval = 0
static

◆ last_values

ulonglong last_values[MAX_MYSQL_VAR]

◆ load_default_groups

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

◆ max_val_length

uint max_val_length
static

◆ max_var_length

uint max_var_length
static

◆ my_end_arg

uint my_end_arg = 0
static

◆ my_long_options

struct my_option my_long_options[]
static

◆ new_line

bool new_line = false
static

◆ nr_iterations

uint nr_iterations
static

◆ opt_bind_addr

char* opt_bind_addr = nullptr
static

◆ opt_compress

bool opt_compress = false
static

◆ opt_compress_algorithm

char* opt_compress_algorithm = nullptr
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 = nullptr
static

◆ opt_enable_cleartext_plugin

uint opt_enable_cleartext_plugin = 0
static

◆ opt_nobeep

bool opt_nobeep
static

◆ opt_plugin_dir

char* opt_plugin_dir = nullptr
static

◆ opt_protocol

uint opt_protocol = 0
static

◆ opt_relative

bool opt_relative = false
static

◆ opt_show_warnings

bool opt_show_warnings = false
static

◆ opt_shutdown_timeout

ulong opt_shutdown_timeout
static

◆ opt_verbose

bool opt_verbose = false
static

◆ opt_vertical

bool opt_vertical = false
static

◆ opt_zstd_compress_level

uint opt_zstd_compress_level = default_zstd_compression_level
static

◆ option_force

bool option_force = false
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]

◆ unix_port

char* unix_port = nullptr
static

◆ user

char* user = nullptr

◆ using_opt_enable_cleartext_plugin

bool using_opt_enable_cleartext_plugin = false
static