Wednesday, December 13

How gdb can help you to solve MySQL problems

What you can do with gdb

  • Check stack traces (and variables), per thread: thread apply all bt [full]
  • Print variables, up to complex one:
  • thread 1
  • print do_command::thd->query_string.string.str
  • Set new values for variables (global and per thread, even those formally read-only in MySQL while it’s running):
  • set max_connections=5000
  • set opt_log_slave_updates=1
  • Call functions (that may do complex changes):
  • call rpl_filter->add_do_db(strdup("hehehe"))
  • Set breakpoints and watchpoints
  • Work interactively or use gdb as a command line utility (-batch)
  • Use macros, Python scripting, more…
  • All these may not work, fail, hang, crash, produce obscure errors…
  • You have to read and understand the source code
Real life case: attaching to alive mysqld

mysql -uroot -e "show variables like 'innodb_autoinc_lock_mode'"
+--------------------------+-------+
| Variable_name             | Value |
+--------------------------+-------+
| innodb_autoinc_lock_mode | 0 |
+--------------------------+-------+

mysql -uroot -e "set global innodb_autoinc_lock_mode=1"

ERROR 1238 (HY000) at line 1: Variable 'innodb_autoinc_lock_mode' is a read only variable

gdb -ex "set innobase_autoinc_lock_mode=1" -batch -p `pidof mysqld

No comments:

Post a Comment