Debugging mysql Client with gdb

I’m not sure if this is the “proper” way to debug mysql, but it’s my latest method:

To run the mysql client in gdb after having built in from a tarball (assuming the current directory is where you build mysql from using a ./BUILD/compile_xxx_debugxxx script):

First, cd to the ./client subdirectory and run the mysql client. (This actually runs a Bourne shell script.)

$ cd client

$ ./mysql

The above might just work (or not). If an error occurs, it will create a file named ./client/.libs/lt-mysql.

(Note: In the same directory as lt-msql is an almost identical executable named mysql. Running the cmp
command on the two shows one byte difference. However, that one byte changes which libmysqlclient.so is used. A comparison of the output of the ldd command with both ./client/.libs/mysql and ./client/.libs/lt-mysql as the single argument shows that lt-mysql uses the
libmysqlclient.so
that exists in the build tree. mysql, on the other hand, uses the library in the standard library path on the box.)

You can debug lt-mysql with gdb:

$ cd .. # Move back up to base mysql source directory

$ gdb ./client/.libs/lt-mysql

(gdb) file ./client/.libs/lt-mysql

(gdb) set arg --socket=/var/lib/mysql/mysql.sock

(gdb) l

I typed the following (much earlier) to trace the Bourne shell version of mysql. (It is what told me about the lt-mysql executable).

$ cd sql

$ sh -x ../client/mysql --socket=/var/lib/mysql/mysql.sock

(Note: There are probably other ways to do the above. Maybe I’ll
eventually discover the “correct” way …)