博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql client 入口
阅读量:4214 次
发布时间:2019-05-26

本文共 1567 字,大约阅读时间需要 5 分钟。

mysql client的入口函数在和sql同级的client 这个目录下,其入口函数是如下:int main(int argc, char *argv[]) {  default_prompt = my_strdup(      PSI_NOT_INSTRUMENTED,      getenv("MYSQL_PS1") ? getenv("MYSQL_PS1") : "mysql> ", MYF(MY_WME));}从这里可以知道,平时我们看到的提示符mysql> 是因为我们没有设置环境变量MYSQL_PS1。我们可以通过这个环境变量来设置自己的命令行提示符。  if (sql_connect(current_host, current_db, current_user, opt_password,                  opt_silent)) {    quick = 1;  // Avoid history    status.exit_status = 1;    mysql_end(-1);  }这里就开始连接server,连接到server后我们就看到下面熟悉的log  put_info("Welcome to the MySQL monitor.  Commands end with ; or \\g.",           INFO_INFO);再往下就是定义三个信号  signal(SIGINT, handle_ctrlc_signal);  // Catch SIGINT to clean up  signal(SIGQUIT, mysql_end);           // Catch SIGQUIT to clean up  signal(SIGHUP, handle_quit_signal);   // Catch SIGHUP to clean up这里有注册三个信号,其中SIGQUIT信号会退出mysql,而sigint其实啥作用都没有void handle_ctrlc_signal(int) {  sigint_received = 1;  /* Skip rest if --sigint-ignore is used. */  if (opt_sigint_ignore) return;  if (executing_query) kill_query("^C");  /* else, do nothing, just terminate the current line (like /c command). */  return;}可以看到如果没有定义opt_sigint_ignore和executing_query,那么用户按ctrl+c其实一点作用都没有最后在main函数开始时候有通过  charset_index = get_command_index('C');来得到C这个命令的index,inline int get_command_index(char cmd_char) {  /*    All client-specific commands are in the first part of commands array    and have a function to implement it.  */#从这里可以知道mysql中支持的clint命令都是在command这个函数中  for (uint i = 0; *commands[i].func != NULL; i++)    if (commands[i].cmd_char == cmd_char) return i;  return -1;}

 

转载地址:http://xinmi.baihongyu.com/

你可能感兴趣的文章
linux find命令详解
查看>>
S3C2440上touchscreen触摸屏驱动
查看>>
USB History Viewing
查看>>
怎样做可靠的分布式锁,Redlock 真的可行么?
查看>>
[图文] Seata AT 模式分布式事务源码分析
查看>>
pm 源码分析
查看>>
Sending the User to Another App
查看>>
kmsg_dump
查看>>
Getting a Result from an Activity
查看>>
Allowing Other Apps to Start Your Activity
查看>>
dev/mem
查看>>
pfn_valid 源码分析
查看>>
dev/kmem 和dev/mem的区别
查看>>
checkbox
查看>>
Sending Simple Data to Other Apps
查看>>
Receiving Simple Data from Other Apps
查看>>
中断API之__tasklet_schedule
查看>>
中断API之enable_irq
查看>>
中断API之disable_irq
查看>>
nova 中的guestfs
查看>>