4

If I run mysqld, ie invoke it directly on the command-line, it survives the shell being closed or hitting ctrl-c.

Is there any way to run it "interactively", ie so that it will shut down if either of those things happen?

(I'd find this useful during development as I have a tmux script to quickly bring up and down various servers.)

mahemoff
  • 331
  • 2
  • 14

2 Answers2

7

You could try --gdb. That will make it respond to SIGINT, though I'm not sure if that has potential to corrupt the database. --one-thread may also be of some help.

Rob N
  • 186
  • 5
2

If installing the initscript and using the standard sudo service mysql start | stop aren't on the list of things you consider reasonable options, you could always compile your own version of mysqld with some custom hackery to the signal handling code in sql/mysqld.cc where it looks like some signals aren't defined yet, so presumably no-ops just waiting for some copy/paste, though there may be additional code that is masking them before this switch is hit.

switch (sig) {
case SIGTERM:
case SIGQUIT:
case SIGKILL:
#ifdef EXTRA_DEBUG
      sql_print_information("Got signal %d to shutdown mysqld",sig);
#endif
      /* switch to the old log message processing */
      logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_FILE:LOG_NONE,
                          opt_log ? LOG_FILE:LOG_NONE);
      DBUG_PRINT("info",("Got signal: %d  abort_loop: %d",sig,abort_loop));
      if (!abort_loop)
      {
        abort_loop=1;       // mark abort for threads
#ifdef HAVE_PSI_THREAD_INTERFACE
        /* Delete the instrumentation for the signal thread */
        PSI_THREAD_CALL(delete_current_thread)();
#endif
#ifdef USE_ONE_SIGNAL_HAND
        pthread_t tmp;
        if (mysql_thread_create(0, /* Not instrumented */
                                &tmp, &connection_attrib, kill_server_thread,
                                (void*) &sig))
          sql_print_error("Can't create thread to kill server");
#else
        kill_server((void*) sig); // MIT THREAD has a alarm thread
#endif
      }
      break;
...

Otherwise, no.

Michael - sqlbot
  • 22,715
  • 2
  • 49
  • 76