MySQL 9.1.0
Source Code Documentation
mysql.cc File Reference
#include "my_config.h"
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <math.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include "client/client_query_attributes.h"
#include "client/include/client_priv.h"
#include "client/include/user_registration.h"
#include "client/multi_option.h"
#include "client/my_readline.h"
#include "client/pattern_matcher.h"
#include "compression.h"
#include "lex_string.h"
#include "m_string.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_default.h"
#include "my_dir.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_macros.h"
#include "mysql/my_loglevel.h"
#include "mysql/plugin_client_telemetry.h"
#include "mysql/strings/int2str.h"
#include "mysql/strings/m_ctype.h"
#include "nulls.h"
#include "str2int.h"
#include "strcont.h"
#include "string_with_len.h"
#include "strmake.h"
#include "strxmov.h"
#include "strxnmov.h"
#include "typelib.h"
#include "violite.h"
#include <sys/ioctl.h>
#include <locale.h>
#include <pwd.h>
#include <curses.h>
#include <term.h>
#include <readline.h>
#include <syslog.h>
#include <mysqld_error.h>
#include <algorithm>
#include <new>
#include "sql-common/net_ns.h"
#include "sql_common.h"
#include "sql_string.h"
#include "client/completion_hash.h"
#include "print_version.h"
#include "welcome_copyright_notice.h"
#include "client/include/authentication_kerberos_clientopt-vars.h"
#include "client/include/authentication_webauthn_clientopt-vars.h"
#include "client/include/caching_sha2_passwordopt-vars.h"
#include "client/include/multi_factor_passwordopt-vars.h"
#include "client/include/sslopt-vars.h"
#include "client/include/multi_factor_passwordopt-longopts.h"
#include "client/include/caching_sha2_passwordopt-longopts.h"
#include "client/include/sslopt-longopts.h"
#include "client/include/authentication_kerberos_clientopt-longopts.h"
#include "client/include/authentication_webauthn_clientopt-longopts.h"
#include "client/include/sslopt-case.h"
#include "client/include/authentication_kerberos_clientopt-case.h"
#include "client/include/authentication_webauthn_clientopt-case.h"
#include <sys/times.h>

Classes

struct  STATUS
 
struct  COMMANDS
 

Macros

#define NOMACROS
 
#define HAVE_READLINE
 
#define USE_POPEN
 
#define MAX_COLUMN_LENGTH   1024
 
#define MAX_SERVER_ARGS   64
 
#define MAX_ALLOCA_SIZE   512
 
#define cmp_database(cs, A, B)   strcmp((A), (B))
 
#define PROMPT_CHAR   '\\'
 
#define DEFAULT_DELIMITER   ";"
 
#define MAX_BATCH_BUFFER_SIZE   (1024L * 1024L * 1024L)
 
#define MY_PRINT_ESC_0   1 /* Replace 0x00 bytes to "\0" */
 
#define MY_PRINT_SPS_0   2 /* Replace 0x00 bytes to space */
 
#define MY_PRINT_XML   4 /* Encode XML entities */
 
#define MY_PRINT_MB   8 /* Recognize multi-byte characters */
 
#define MY_PRINT_CTRL   16 /* Replace TAB, NL, CR to "\t", "\n", "\r" */
 
#define ff2s_check_flag(X)
 

Typedefs

typedef enum enum_info_type INFO_TYPE
 

Enumerations

enum  enum_info_type { INFO_INFO , INFO_ERROR , INFO_RESULT }
 

Functions

static const std::string HI_DEFAULTS ("*IDENTIFIED*:*PASSWORD*")
 default set of patterns used for history exclusion filter More...
 
static void usage (int version)
 
void tee_write (FILE *file, const char *s, size_t slen, int flags)
 Write data to a stream. More...
 
void tee_fprintf (FILE *file, const char *fmt,...)
 
void tee_fputs (const char *s, FILE *file)
 
void tee_puts (const char *s, FILE *file)
 
void tee_putc (int c, FILE *file)
 
static void tee_print_sized_data (const char *, unsigned int, unsigned int, bool)
 
static int get_options (int *argc_ptr, char ***argv_ptr)
 
bool get_one_option (int optid, const struct my_option *opt, char *argument)
 
static int com_quit (String *buffer, char *)
 
static int com_go (String *buffer, char *)
 
static int com_ego (String *buffer, char *)
 
static int com_print (String *buffer, char *)
 
static int com_help (String *buffer, char *)
 
static int com_clear (String *buffer, char *)
 
static int com_connect (String *buffer, char *)
 
static int com_status (String *buffer, char *)
 
static int com_use (String *buffer, char *)
 
static int com_source (String *buffer, char *)
 
static int com_rehash (String *buffer, char *)
 
static int com_tee (String *buffer, char *)
 
static int com_notee (String *buffer, char *)
 
static int com_charset (String *buffer, char *)
 
static int com_prompt (String *buffer, char *)
 
static int com_delimiter (String *buffer, char *)
 
static int com_warnings (String *buffer, char *)
 
static int com_nowarnings (String *buffer, char *)
 
static int com_resetconnection (String *buffer, char *)
 
static int com_query_attributes (String *buffer, char *)
 
static int com_ssl_session_data_print (String *buffer, char *)
 
static int com_shell (String *buffer, char *)
 
static int com_nopager (String *buffer, char *)
 
static int com_pager (String *buffer, char *)
 
static int com_edit (String *buffer, char *)
 
static int read_and_execute (bool interactive)
 
static bool init_connection_options (MYSQL *mysql)
 
static int sql_connect (char *host, char *database, char *user, uint silent)
 
static const char * server_version_string (MYSQL *con)
 
static int put_info (const char *str, INFO_TYPE info, uint error=0, const char *sqlstate=nullptr)
 
static int put_error (MYSQL *con)
 
static void put_error_if_any (MYSQL *con)
 Prints the SQL error, if any. More...
 
static void safe_put_field (const char *pos, ulong length)
 
static void xmlencode_print (const char *src, uint length)
 
static void init_pager ()
 
static void end_pager ()
 
static void init_tee (const char *)
 
static void end_tee ()
 
static const char * construct_prompt ()
 
static void reset_prompt (char *in_string, bool *ml_comment)
 
static char * get_arg (char *line, bool get_next_arg)
 
static void init_username ()
 
static void add_int_to_prompt (int toadd)
 
static int get_result_width (MYSQL_RES *result)
 For a new result, return the max number of characters that any upcoming row may return. More...
 
static int get_field_disp_length (MYSQL_FIELD *field)
 Return the length of a field after it would be rendered into text. More...
 
static int normalize_dbname (const char *line, char *buff, uint buff_size)
 Normalize database name. More...
 
static int get_quote_count (const char *line)
 
static void add_filtered_history (const char *string)
 
static void add_syslog (const char *line)
 
static void fix_line (String *final_command)
 
static void get_current_os_user ()
 
static void get_current_os_sudouser ()
 
static char * skip_over_comments_and_space (char *ptr, size_t length)
 Skips over possible multi-line comments (/ * and * /) and whitespace and finds the first non-comment command. More...
 
static void trim_leading_comments_and_space (String *buffer, const char *skip_comments_start)
 Trims the leading comments and whitespace from a command. More...
 
int add_history (const char *command)
 
int read_history (const char *command)
 
int write_history (const char *command)
 
HIST_ENTRY * history_get (int num)
 
static int not_in_history (const char *line)
 
static void initialize_readline (char *name)
 
static COMMANDSfind_command (char *name)
 It checks if the input is a long form command. More...
 
static COMMANDSfind_command (char cmd_char)
 It checks if the input is a short form command. More...
 
static bool add_line (String &buffer, char *line, size_t line_length, char *in_string, bool *ml_comment, bool truncated)
 
static void remove_cntrl (String *buffer)
 
static void print_table_data (MYSQL_RES *result)
 
static void print_table_data_html (MYSQL_RES *result)
 
static void print_table_data_xml (MYSQL_RES *result)
 
static void print_tab_data (MYSQL_RES *result)
 
static void print_table_data_vertically (MYSQL_RES *result)
 
static void print_warnings ()
 
static ulong start_timer ()
 
static void end_timer (ulong start_time, char *buff)
 
static void mysql_end_timer (ulong start_time, char *buff)
 
static void nice_time (double sec, char *buff, bool part_second)
 Write as many as 52+1 bytes to buff, in the form of a legible duration of time. More...
 
static void kill_query (const char *reason)
 
void mysql_end (int sig)
 
void handle_ctrlc_signal (int)
 SIGINT signal handler. More...
 
void handle_quit_signal (int sig)
 Handler to perform a cleanup and quit the program. More...
 
static void window_resize (int)
 
bool is_delimiter_command (const char *name, ulong len)
 
int get_command_index (char cmd_char)
 Get the index of a command in the commands array. More...
 
static bool server_supports_dollar_quote (MYSQL *con)
 
int main (int argc, char *argv[])
 
static size_t check_for_dollar_quote (const char *pos, const char *last_end_of_mb_pos, const char *start_of_line, const char *end_of_line)
 Check if there is a dollar quote at current position. More...
 
static char * new_command_generator (const char *text, int)
 
static char ** new_mysql_completion (const char *text, int start, int end)
 
char * no_completion (const char *, int)
 
static int fake_magic_space (int, int)
 
static void build_completion_hash (bool rehash, bool write_info)
 
static int reconnect ()
 
static bool get_current_db ()
 Checks the current DB and updates the global variable current_db If the command fails hen he current_db is set to nullptr. More...
 
static int mysql_real_query_for_lazy (const char *buf, size_t length, bool set_params=false)
 
static int mysql_store_result_for_lazy (MYSQL_RES **result)
 
static void print_help_item (MYSQL_ROW *cur, int num_name, int num_cat, char *last_char)
 
static int com_server_help (String *buffer, char *line, char *help_arg)
 
static int com_go_impl (String *buffer, char *line)
 
static void telemetry_carrier_set (void *carrier_data, const char *key, size_t key_length, const char *value, size_t value_length)
 
const char * fieldtype2str (enum enum_field_types type)
 
static char * fieldflags2str (uint f)
 
static void print_field_types (MYSQL_RES *result)
 
static bool is_binary_field (MYSQL_FIELD *field)
 
static void print_as_hex (FILE *output_file, const char *str, ulong len, ulong total_bytes_to_send)
 
static const char * array_value (const char **array, char key)
 
static int sql_real_connect (char *host, char *database, char *user, char *, uint silent)
 

Variables

const char * VER = "14.14"
 
static char * server_version = nullptr
 
client_query_attributestelemetry_client_attrs = nullptr
 
static Pattern_matcher ignore_matcher
 used for matching which history lines to ignore More...
 
static HashTable ht
 
static MEM_ROOT argv_alloc {PSI_NOT_INSTRUMENTED, 512}
 
static MYSQL mysql_handle
 
static bool ignore_errors = false
 
static bool wait_flag = false
 
static bool quick = false
 
static bool connected = false
 
static bool opt_raw_data = false
 
static bool unbuffered = false
 
static bool output_tables = false
 
static bool opt_rehash = true
 
static bool skip_updates = false
 
static bool safe_updates = false
 
static bool one_database = false
 
static bool opt_compress = false
 
static bool using_opt_local_infile = false
 
static bool vertical = false
 
static bool line_numbers = true
 
static bool column_names = true
 
static bool opt_html = false
 
static bool opt_xml = false
 
static bool opt_nopager = true
 
static bool opt_outfile = false
 
static bool named_cmds = false
 
static bool opt_nobeep = false
 
static bool opt_reconnect = true
 
static bool default_pager_set = false
 
static bool opt_sigint_ignore = false
 
static bool auto_vertical_output = false
 
static bool show_warnings = false
 
static bool executing_query = false
 
static bool interrupted_query = false
 
static bool ignore_spaces = false
 
static bool sigint_received = false
 
static bool opt_syslog = false
 
static bool opt_binhex = false
 
static bool opt_binary_as_hex_set_explicitly = false
 
static bool debug_info_flag
 
static bool debug_check_flag
 
static bool column_types_flag
 
static bool preserve_comments = true
 
static ulong opt_max_allowed_packet
 
static ulong opt_net_buffer_length
 
static uint verbose = 0
 
static uint opt_silent = 0
 
static uint opt_mysql_port = 0
 
static uint opt_local_infile = 0
 
static uint opt_enable_cleartext_plugin = 0
 
static bool using_opt_enable_cleartext_plugin = false
 
static uint my_end_arg
 
static char * opt_mysql_unix_port = nullptr
 
static char * opt_bind_addr = nullptr
 
static int connect_flag = CLIENT_INTERACTIVE
 
static bool opt_binary_mode = false
 
static bool opt_connect_expired_password = false
 
static char * current_host
 
static char * dns_srv_name
 
static char * current_db
 
static char * current_user = nullptr
 
static char * current_prompt = nullptr
 
static char * delimiter_str = nullptr
 
static const char * default_charset = MYSQL_AUTODETECT_CHARSET_NAME
 
static char * histfile
 
static char * histfile_tmp
 
static char * opt_histignore = nullptr
 
static String glob_buffer
 
static String old_buffer
 
static String processed_prompt
 
static String dollar_quote
 
static bool dollar_quote_supported = false
 
static char * full_username = nullptr
 
static char * part_username = nullptr
 
static char * default_prompt = nullptr
 
static char * current_os_user = nullptr
 
static char * current_os_sudouser = nullptr
 
static int wait_time = 5
 
static STATUS status
 
static ulong select_limit
 
static ulong max_join_size
 
static ulong opt_connect_timeout = 0
 
static char mysql_charsets_dir [FN_REFLEN+1]
 
static char * opt_plugin_dir = nullptr
 
static char * opt_default_auth = nullptr
 
static char * opt_load_data_local_dir = nullptr
 
static char * opt_network_namespace = nullptr
 
static const char * xmlmeta []
 
static const char * day_names []
 
static const char * month_names []
 
static char default_pager [FN_REFLEN]
 
static char pager [FN_REFLEN]
 
static char outfile [FN_REFLEN]
 
static FILE * PAGER
 
static FILE * OUTFILE
 
static MEM_ROOT hash_mem_root (PSI_NOT_INSTRUMENTED, 16384)
 
static uint prompt_counter
 
static char delimiter [16] = DEFAULT_DELIMITER
 
static size_t delimiter_length = 1
 
unsigned short terminal_width = 80
 
static uint opt_zstd_compress_level = default_zstd_compression_level
 
static char * opt_compress_algorithm = nullptr
 
static uint opt_protocol = 0
 
static const CHARSET_INFOcharset_info = &my_charset_latin1
 
static char * opt_oci_config_file = nullptr
 
static char * opt_authentication_oci_client_config_profile = nullptr
 
static char * opt_authentication_openid_connect_client_id_token_file = nullptr
 
static char * opt_register_factor = nullptr
 
static bool opt_tel_plugin = false
 
static const char * opt_tel_plugin_name = "telemetry_client"
 
static bool opt_system_command = false
 
static struct my_option my_empty_options []
 
const char * default_dbug_option = "d:t:o,/tmp/mysql.trace"
 
static void * ssl_session_data = nullptr
 
static Multi_option opt_init_commands
 
static bool opt_build_completion_hash = false
 
static COMMANDS commands []
 
static const char * load_default_groups [] = {"mysql", "client", nullptr}
 
int history_length
 
const char DELIMITER_NAME [] = "delimiter"
 
const uint DELIMITER_NAME_LEN = sizeof(DELIMITER_NAME) - 1
 
static int delimiter_index = -1
 
static int charset_index = -1
 
static bool real_binary_mode = false
 
static struct my_option my_long_options []
 

Macro Definition Documentation

◆ cmp_database

#define cmp_database (   cs,
  A,
 
)    strcmp((A), (B))

◆ DEFAULT_DELIMITER

#define DEFAULT_DELIMITER   ";"

◆ ff2s_check_flag

#define ff2s_check_flag (   X)
Value:
if (f & X##_FLAG) { \
s = my_stpcpy(s, #X " "); \
f &= ~X##_FLAG; \
}
static char * my_stpcpy(char *dst, const char *src)
Copy a string from src to dst until (and including) terminating null byte.
Definition: m_string.h:142
#define X(b)
Definition: xcom_base.cc:9161

◆ HAVE_READLINE

#define HAVE_READLINE

◆ MAX_ALLOCA_SIZE

#define MAX_ALLOCA_SIZE   512

◆ MAX_BATCH_BUFFER_SIZE

#define MAX_BATCH_BUFFER_SIZE   (1024L * 1024L * 1024L)

◆ MAX_COLUMN_LENGTH

#define MAX_COLUMN_LENGTH   1024

◆ MAX_SERVER_ARGS

#define MAX_SERVER_ARGS   64

◆ MY_PRINT_CTRL

#define MY_PRINT_CTRL   16 /* Replace TAB, NL, CR to "\t", "\n", "\r" */

◆ MY_PRINT_ESC_0

#define MY_PRINT_ESC_0   1 /* Replace 0x00 bytes to "\0" */

◆ MY_PRINT_MB

#define MY_PRINT_MB   8 /* Recognize multi-byte characters */

◆ MY_PRINT_SPS_0

#define MY_PRINT_SPS_0   2 /* Replace 0x00 bytes to space */

◆ MY_PRINT_XML

#define MY_PRINT_XML   4 /* Encode XML entities */

◆ NOMACROS

#define NOMACROS

◆ PROMPT_CHAR

#define PROMPT_CHAR   '\\'

◆ USE_POPEN

#define USE_POPEN

Typedef Documentation

◆ INFO_TYPE

typedef enum enum_info_type INFO_TYPE

Enumeration Type Documentation

◆ enum_info_type

Enumerator
INFO_INFO 
INFO_ERROR 
INFO_RESULT 

Function Documentation

◆ add_filtered_history()

static void add_filtered_history ( const char *  string)
static

◆ add_history()

int add_history ( const char *  command)

◆ add_int_to_prompt()

static void add_int_to_prompt ( int  toadd)
static

◆ add_line()

static bool add_line ( String buffer,
char *  line,
size_t  line_length,
char *  in_string,
bool *  ml_comment,
bool  truncated 
)
static

◆ add_syslog()

void add_syslog ( const char *  line)
static

◆ array_value()

static const char * array_value ( const char **  array,
char  key 
)
static

◆ build_completion_hash()

static void build_completion_hash ( bool  rehash,
bool  write_info 
)
static

◆ check_for_dollar_quote()

static size_t check_for_dollar_quote ( const char *  pos,
const char *  last_end_of_mb_pos,
const char *  start_of_line,
const char *  end_of_line 
)
static

Check if there is a dollar quote at current position.

Parameters
posCurrent position of input line
last_end_of_mb_posLast byte of previous multi-byte character. Used to check if preceeding char is an mb char.
start_of_lineStart of input line
end_of_lineEnd of input line
Returns
length of dollar quote, 0 if not found

◆ com_charset()

static int com_charset ( String buffer,
char *  line 
)

◆ com_clear()

static int com_clear ( String buffer,
char *  line 
)

◆ com_connect()

static int com_connect ( String buffer,
char *  line 
)

◆ com_delimiter()

static int com_delimiter ( String buffer,
char *  line 
)

◆ com_edit()

static int com_edit ( String buffer,
char *  line 
)

◆ com_ego()

static int com_ego ( String buffer,
char *  line 
)

◆ com_go()

static int com_go ( String buffer,
char *  line 
)

◆ com_go_impl()

static int com_go_impl ( String buffer,
char *  line 
)
static

◆ com_help()

static int com_help ( String buffer,
char *  line 
)

◆ com_nopager()

static int com_nopager ( String buffer,
char *  line 
)
static

◆ com_notee()

static int com_notee ( String buffer,
char *  line 
)

◆ com_nowarnings()

static int com_nowarnings ( String buffer,
char *  line 
)

◆ com_pager()

static int com_pager ( String buffer,
char *  line 
)

◆ com_print()

static int com_print ( String buffer,
char *  line 
)

◆ com_prompt()

static int com_prompt ( String buffer,
char *  line 
)

◆ com_query_attributes()

static int com_query_attributes ( String buffer,
char *  line 
)

◆ com_quit()

static int com_quit ( String buffer,
char *  line 
)
static

◆ com_rehash()

static int com_rehash ( String buffer,
char *  line 
)

◆ com_resetconnection()

static int com_resetconnection ( String buffer,
char *  line 
)

◆ com_server_help()

static int com_server_help ( String buffer,
char *  line,
char *  help_arg 
)
static

◆ com_shell()

static int com_shell ( String buffer,
char *  line 
)
static

◆ com_source()

static int com_source ( String buffer,
char *  line 
)

◆ com_ssl_session_data_print()

static int com_ssl_session_data_print ( String buffer,
char *  line 
)

◆ com_status()

static int com_status ( String buffer,
char *  line 
)

◆ com_tee()

static int com_tee ( String buffer,
char *  line 
)

◆ com_use()

static int com_use ( String buffer,
char *  line 
)

◆ com_warnings()

static int com_warnings ( String buffer,
char *  line 
)

◆ construct_prompt()

static const char * construct_prompt ( )
static

◆ end_pager()

static void end_pager ( )
static

◆ end_tee()

static void end_tee ( )
static

◆ end_timer()

static void end_timer ( ulong  start_time,
char *  buff 
)
static

◆ fake_magic_space()

static int fake_magic_space ( int  ,
int   
)
static

◆ fieldflags2str()

static char * fieldflags2str ( uint  f)
static

◆ fieldtype2str()

const char * fieldtype2str ( enum enum_field_types  type)

◆ find_command() [1/2]

static COMMANDS * find_command ( char *  name)
static

It checks if the input is a long form command.

It returns the command's pointer if a command is found, else return NULL. Note that if binary-mode is set, then only DELIMITER is searched for.

Parameters
nameA string.
Returns
the command's pointer or NULL.

◆ find_command() [2/2]

static COMMANDS * find_command ( char  cmd_char)
static

It checks if the input is a short form command.

It returns the command's pointer if a command is found, else return NULL. Note that if binary-mode is set, then only \C is searched for.

Parameters
cmd_charA character of one byte.
Returns
the command's pointer or NULL.

◆ fix_line()

static void fix_line ( String final_command)
static

◆ get_arg()

char * get_arg ( char *  line,
bool  get_next_arg 
)
static

◆ get_command_index()

int get_command_index ( char  cmd_char)
inline

Get the index of a command in the commands array.

Parameters
cmd_charShort form command.
Returns
int The index of the command is returned if it is found, else -1 is returned.

◆ get_current_db()

static bool get_current_db ( )
static

Checks the current DB and updates the global variable current_db If the command fails hen he current_db is set to nullptr.

Returns
Error state
Return values
trueAn error occurred
falseSuccess; current_db is updated

◆ get_current_os_sudouser()

static void get_current_os_sudouser ( )
static

◆ get_current_os_user()

static void get_current_os_user ( )
static

◆ get_field_disp_length()

static int get_field_disp_length ( MYSQL_FIELD field)
static

Return the length of a field after it would be rendered into text.

This doesn't know or care about multibyte characters. Assume we're using such a charset. We can't know that all of the upcoming rows for this column will have bytes that each render into some fraction of a character. It's at least possible that a row has bytes that all render into one character each, and so the maximum length is still the number of bytes. (Assumption 1: This can't be better because we can never know the number of characters that the DB is going to send – only the number of bytes. 2: Chars <= Bytes.)

Parameters
fieldPointer to a field to be inspected
Returns
number of character positions to be used, at most

◆ get_one_option()

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

◆ get_options()

static int get_options ( int *  argc_ptr,
char ***  argv_ptr 
)
static

◆ get_quote_count()

static int get_quote_count ( const char *  line)
static

◆ get_result_width()

static int get_result_width ( MYSQL_RES result)
static

For a new result, return the max number of characters that any upcoming row may return.

Parameters
resultPointer to the result to judge
Returns
The max number of characters in any row of this result

◆ handle_ctrlc_signal()

void handle_ctrlc_signal ( int  )

SIGINT signal handler.

This function handles SIGINT (Ctrl - C). It sends a 'KILL [QUERY]' command to the server if a query is currently executing. On Windows, 'Ctrl - Break' is treated alike.

FIXME: POSIX allows only a very limited set of interactions from signal handlers, as the main thread could have nearly any state at the time of the signal and is suspended until the signal handler returns. In particular, only variables of type sig_atomic_t can be set and tested, and most C library functions (including malloc()) are banned. Thus, calling kill_query() here is forbidden and should not be done.

◆ handle_quit_signal()

void handle_quit_signal ( int  sig)

Handler to perform a cleanup and quit the program.

This function would send a 'KILL [QUERY]' command to the server if a query is currently executing and then it invokes mysql_thread_end()/ mysql_end() in order to terminate the mysql client process.

Parameters
sigSignal number

◆ HI_DEFAULTS()

static const std::string HI_DEFAULTS ( "*IDENTIFIED*:*PASSWORD*"  )
static

default set of patterns used for history exclusion filter

◆ history_get()

HIST_ENTRY * history_get ( int  num)

◆ init_connection_options()

static bool init_connection_options ( MYSQL mysql)
static

◆ init_pager()

static void init_pager ( )
static

◆ init_tee()

static void init_tee ( const char *  file_name)
static

◆ init_username()

static void init_username ( )
static

◆ initialize_readline()

static void initialize_readline ( char *  name)
static

◆ is_binary_field()

static bool is_binary_field ( MYSQL_FIELD field)
static

◆ is_delimiter_command()

bool is_delimiter_command ( const char *  name,
ulong  len 
)
inline

◆ kill_query()

static void kill_query ( const char *  reason)
static

◆ main()

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

◆ mysql_end()

void mysql_end ( int  sig)

◆ mysql_end_timer()

static void mysql_end_timer ( ulong  start_time,
char *  buff 
)
static

◆ mysql_real_query_for_lazy()

static int mysql_real_query_for_lazy ( const char *  buf,
size_t  length,
bool  set_params = false 
)
static

◆ mysql_store_result_for_lazy()

static int mysql_store_result_for_lazy ( MYSQL_RES **  result)
static

◆ new_command_generator()

static char * new_command_generator ( const char *  text,
int  state 
)
static

◆ new_mysql_completion()

static char ** new_mysql_completion ( const char *  text,
int  start,
int  end 
)
static

◆ nice_time()

static void nice_time ( double  sec,
char *  buff,
bool  part_second 
)
static

Write as many as 52+1 bytes to buff, in the form of a legible duration of time.

len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds") -> 52

◆ no_completion()

char * no_completion ( const char *  ,
int   
)

◆ normalize_dbname()

static int normalize_dbname ( const char *  line,
char *  buff,
uint  buff_size 
)
static

Normalize database name.

Parameters
[in]lineThe command.
[out]buffNormalized db name.
[in]buff_sizeBuffer size.
Returns
Operation status
Return values
0Success
1Failure
Note
Sometimes server normalizes the database names & APIs like mysql_select_db() expect normalized database names. Since it is difficult to perform the name conversion/normalization on the client side, this function tries to get the normalized dbname (indirectly) from the server.

◆ not_in_history()

static int not_in_history ( const char *  line)
static

◆ print_as_hex()

static void print_as_hex ( FILE *  output_file,
const char *  str,
ulong  len,
ulong  total_bytes_to_send 
)
static

◆ print_field_types()

static void print_field_types ( MYSQL_RES result)
static

◆ print_help_item()

static void print_help_item ( MYSQL_ROW cur,
int  num_name,
int  num_cat,
char *  last_char 
)
static

◆ print_tab_data()

static void print_tab_data ( MYSQL_RES result)
static

◆ print_table_data()

static void print_table_data ( MYSQL_RES result)
static

◆ print_table_data_html()

static void print_table_data_html ( MYSQL_RES result)
static

◆ print_table_data_vertically()

static void print_table_data_vertically ( MYSQL_RES result)
static

◆ print_table_data_xml()

static void print_table_data_xml ( MYSQL_RES result)
static

◆ print_warnings()

static void print_warnings ( )
static

◆ put_error()

static int put_error ( MYSQL con)
static

◆ put_error_if_any()

static void put_error_if_any ( MYSQL con)
static

Prints the SQL error, if any.

Similar to put_error, but prints the error only if there is any.

Parameters
conthe connection to check for errors

◆ put_info()

static int put_info ( const char *  str,
INFO_TYPE  info,
uint  error = 0,
const char *  sqlstate = nullptr 
)
static

◆ read_and_execute()

static int read_and_execute ( bool  interactive)
static

◆ read_history()

int read_history ( const char *  command)

◆ reconnect()

static int reconnect ( )
static

◆ remove_cntrl()

static void remove_cntrl ( String buffer)
static

◆ reset_prompt()

static void reset_prompt ( char *  in_string,
bool *  ml_comment 
)
inlinestatic

◆ safe_put_field()

static void safe_put_field ( const char *  pos,
ulong  length 
)
static

◆ server_supports_dollar_quote()

static bool server_supports_dollar_quote ( MYSQL con)
static

◆ server_version_string()

static const char * server_version_string ( MYSQL con)
static

◆ skip_over_comments_and_space()

static char * skip_over_comments_and_space ( char *  ptr,
size_t  length 
)
static

Skips over possible multi-line comments (/ * and * /) and whitespace and finds the first non-comment command.

We only have to worry about multi-line comments since the single line comments (//foo) are sent immediately to the server anyway

Parameters
ptrPointer to the start of the command
lengthThe length of the command text in ptr
Returns
the first non-comment and non-whitespace command.
See also
trim_leading_comments_and_space

◆ sql_connect()

static int sql_connect ( char *  host,
char *  database,
char *  user,
uint  silent 
)
static

◆ sql_real_connect()

static int sql_real_connect ( char *  host,
char *  database,
char *  user,
char *  ,
uint  silent 
)
static

◆ start_timer()

static ulong start_timer ( )
static

◆ tee_fprintf()

void tee_fprintf ( FILE *  file,
const char *  fmt,
  ... 
)

◆ tee_fputs()

void tee_fputs ( const char *  s,
FILE *  file 
)

◆ tee_print_sized_data()

static void tee_print_sized_data ( const char *  data,
unsigned int  data_length,
unsigned int  total_bytes_to_send,
bool  right_justified 
)
static

◆ tee_putc()

void tee_putc ( int  c,
FILE *  file 
)

◆ tee_puts()

void tee_puts ( const char *  s,
FILE *  file 
)

◆ tee_write()

void tee_write ( FILE *  file,
const char *  s,
size_t  slen,
int  flags 
)

Write data to a stream.

Various modes, corresponding to –tab, –xml, –raw parameters, are supported.

Parameters
fileStream to write to
sString to write
slenString length
flagsFlags for –tab, –xml, –raw.

◆ telemetry_carrier_set()

static void telemetry_carrier_set ( void *  carrier_data,
const char *  key,
size_t  key_length,
const char *  value,
size_t  value_length 
)
static

◆ trim_leading_comments_and_space()

static void trim_leading_comments_and_space ( String buffer,
const char *  skip_comments_start 
)
static

Trims the leading comments and whitespace from a command.

Useful when skip_over_comments_and_space is used to find if there is something to skip and now it needs to be skipped. Note that the the function expects that skip_comments_start is within buffer.

Note
The idea is that we first look skip non-destructively over the comments and space and then check if it's a MySQL command or not. If it is we then trip the leading comments and space and proceed. If not we send the comments and the command to the server.
Parameters
[in,out]bufferThe string buffer containing the command + the comments/whitespace
skip_comments_startThe place where leading comments end and the actual command starts

◆ usage()

static void usage ( int  version)
static

◆ window_resize()

void window_resize ( int  )
static

◆ write_history()

int write_history ( const char *  command)

◆ xmlencode_print()

static void xmlencode_print ( const char *  src,
uint  length 
)
static

Variable Documentation

◆ argv_alloc

MEM_ROOT argv_alloc {PSI_NOT_INSTRUMENTED, 512}
static

◆ auto_vertical_output

bool auto_vertical_output = false
static

◆ charset_index

int charset_index = -1
static

◆ charset_info

const CHARSET_INFO* charset_info = &my_charset_latin1
static

◆ column_names

bool column_names = true
static

◆ column_types_flag

bool column_types_flag
static

◆ commands

COMMANDS commands[]
static

◆ connect_flag

int connect_flag = CLIENT_INTERACTIVE
static

◆ connected

bool connected = false
static

◆ current_db

char* current_db
static

◆ current_host

char* current_host
static

◆ current_os_sudouser

char * current_os_sudouser = nullptr
static

◆ current_os_user

char* current_os_user = nullptr
static

◆ current_prompt

char* current_prompt = nullptr
static

◆ current_user

char* current_user = nullptr
static

◆ day_names

const char* day_names[]
static
Initial value:
= {"Sun", "Mon", "Tue", "Wed",
"Thu", "Fri", "Sat"}

◆ debug_check_flag

bool debug_check_flag
static

◆ debug_info_flag

bool debug_info_flag
static

◆ default_charset

const char* default_charset = MYSQL_AUTODETECT_CHARSET_NAME
static

◆ default_dbug_option

const char* default_dbug_option = "d:t:o,/tmp/mysql.trace"

◆ default_pager

char default_pager[FN_REFLEN]
static

◆ default_pager_set

bool default_pager_set = false
static

◆ default_prompt

char * default_prompt = nullptr
static

◆ delimiter

char delimiter[16] = DEFAULT_DELIMITER
static

◆ delimiter_index

int delimiter_index = -1
static

◆ delimiter_length

size_t delimiter_length = 1
static

◆ DELIMITER_NAME

const char DELIMITER_NAME[] = "delimiter"

◆ DELIMITER_NAME_LEN

const uint DELIMITER_NAME_LEN = sizeof(DELIMITER_NAME) - 1

◆ delimiter_str

char* delimiter_str = nullptr
static

◆ dns_srv_name

char* dns_srv_name
static

◆ dollar_quote

String dollar_quote
static

◆ dollar_quote_supported

bool dollar_quote_supported = false
static

◆ executing_query

bool executing_query = false
static

◆ full_username

char* full_username = nullptr
static

◆ glob_buffer

String glob_buffer
static

◆ hash_mem_root

MEM_ROOT hash_mem_root(PSI_NOT_INSTRUMENTED, 16384) ( PSI_NOT_INSTRUMENTED  ,
16384   
)
static

◆ histfile

char* histfile
static

◆ histfile_tmp

char* histfile_tmp
static

◆ history_length

int history_length

◆ ht

HashTable ht
static

◆ ignore_errors

bool ignore_errors = false
static

◆ ignore_matcher

Pattern_matcher ignore_matcher
static

used for matching which history lines to ignore

◆ ignore_spaces

bool ignore_spaces = false
static

◆ interrupted_query

bool interrupted_query = false
static

◆ line_numbers

bool line_numbers = true
static

◆ load_default_groups

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

◆ max_join_size

ulong max_join_size
static

◆ month_names

const char* month_names[]
static
Initial value:
= {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}

◆ my_empty_options

struct my_option my_empty_options[]
static
Initial value:
= {
{nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0,
0, nullptr, 0, nullptr}}
#define GET_NO_ARG
Definition: my_getopt.h:44
@ NO_ARG
Definition: my_getopt.h:81

◆ my_end_arg

uint my_end_arg
static

◆ my_long_options

struct my_option my_long_options[]
static

◆ mysql_charsets_dir

char mysql_charsets_dir[FN_REFLEN+1]
static

◆ mysql_handle

MYSQL mysql_handle
static

◆ named_cmds

bool named_cmds = false
static

◆ old_buffer

String old_buffer
static

◆ one_database

bool one_database = false
static

◆ opt_authentication_oci_client_config_profile

char* opt_authentication_oci_client_config_profile = nullptr
static

◆ opt_authentication_openid_connect_client_id_token_file

char* opt_authentication_openid_connect_client_id_token_file = nullptr
static

◆ opt_binary_as_hex_set_explicitly

bool opt_binary_as_hex_set_explicitly = false
static

◆ opt_binary_mode

bool opt_binary_mode = false
static

◆ opt_bind_addr

char* opt_bind_addr = nullptr
static

◆ opt_binhex

bool opt_binhex = false
static

◆ opt_build_completion_hash

bool opt_build_completion_hash = false
static

◆ opt_compress

bool opt_compress = false
static

◆ opt_compress_algorithm

char* opt_compress_algorithm = nullptr
static

◆ opt_connect_expired_password

bool opt_connect_expired_password = false
static

◆ opt_connect_timeout

ulong opt_connect_timeout = 0
static

◆ opt_default_auth

char * opt_default_auth = nullptr
static

◆ opt_enable_cleartext_plugin

uint opt_enable_cleartext_plugin = 0
static

◆ opt_histignore

char* opt_histignore = nullptr
static

◆ opt_html

bool opt_html = false
static

◆ opt_init_commands

Multi_option opt_init_commands
static

◆ opt_load_data_local_dir

char* opt_load_data_local_dir = nullptr
static

◆ opt_local_infile

uint opt_local_infile = 0
static

◆ opt_max_allowed_packet

ulong opt_max_allowed_packet
static

◆ opt_mysql_port

uint opt_mysql_port = 0
static

◆ opt_mysql_unix_port

char* opt_mysql_unix_port = nullptr
static

◆ opt_net_buffer_length

ulong opt_net_buffer_length
static

◆ opt_network_namespace

char* opt_network_namespace = nullptr
static

◆ opt_nobeep

bool opt_nobeep = false
static

◆ opt_nopager

bool opt_nopager = true
static

◆ opt_oci_config_file

char* opt_oci_config_file = nullptr
static

◆ opt_outfile

bool opt_outfile = false
static

◆ opt_plugin_dir

char* opt_plugin_dir = nullptr
static

◆ opt_protocol

uint opt_protocol = 0
static

◆ opt_raw_data

bool opt_raw_data = false
static

◆ opt_reconnect

bool opt_reconnect = true
static

◆ opt_register_factor

char* opt_register_factor = nullptr
static

◆ opt_rehash

bool opt_rehash = true
static

◆ opt_sigint_ignore

bool opt_sigint_ignore = false
static

◆ opt_silent

uint opt_silent = 0
static

◆ opt_syslog

bool opt_syslog = false
static

◆ opt_system_command

bool opt_system_command = false
static

◆ opt_tel_plugin

bool opt_tel_plugin = false
static

◆ opt_tel_plugin_name

const char* opt_tel_plugin_name = "telemetry_client"
static

◆ opt_xml

bool opt_xml = false
static

◆ opt_zstd_compress_level

uint opt_zstd_compress_level = default_zstd_compression_level
static

◆ outfile

char outfile[FN_REFLEN]
static

◆ OUTFILE

FILE * OUTFILE
static

◆ output_tables

bool output_tables = false
static

◆ pager

char pager[FN_REFLEN]
static

◆ PAGER

FILE* PAGER
static

◆ part_username

char * part_username = nullptr
static

◆ preserve_comments

bool preserve_comments = true
static

◆ processed_prompt

String processed_prompt
static

◆ prompt_counter

uint prompt_counter
static

◆ quick

bool quick = false
static

◆ real_binary_mode

bool real_binary_mode = false
static

◆ safe_updates

bool safe_updates = false
static

◆ select_limit

ulong select_limit
static

◆ server_version

char* server_version = nullptr
static

◆ show_warnings

bool show_warnings = false
static

◆ sigint_received

bool sigint_received = false
static

◆ skip_updates

bool skip_updates = false
static

◆ ssl_session_data

void* ssl_session_data = nullptr
static

◆ status

STATUS status
static

◆ telemetry_client_attrs

client_query_attributes* telemetry_client_attrs = nullptr

◆ terminal_width

unsigned short terminal_width = 80

◆ unbuffered

bool unbuffered = false
static

◆ using_opt_enable_cleartext_plugin

bool using_opt_enable_cleartext_plugin = false
static

◆ using_opt_local_infile

bool using_opt_local_infile = false
static

◆ VER

const char* VER = "14.14"

◆ verbose

uint verbose = 0
static

◆ vertical

bool vertical = false
static

◆ wait_flag

bool wait_flag = false
static

◆ wait_time

int wait_time = 5
static

◆ xmlmeta

const char* xmlmeta[]
static
Initial value:
= {
"&", "&amp;", "<", "&lt;", ">", "&gt;", "\"", "&quot;",
"\0", " ", nullptr, nullptr}