how to debug mysql with gdb .

Posted on 2012-04-09
Medium Priority
Last Modified: 2012-06-27
i am trying to learn how to use Gdb to debug mysql. i read quite  a lot website in google .. but could not straight my head ..

now from documentation ,, its saying, i need to start mysqld with gdb ..

but the way i run mysql like bellow

/opt/mysql/mysqlserver5/bin/mysqld_safe --user=mysql &

but if i use gdb infront of this command , its say, its not a binary ..
can any one tell me..

how to use gdb with mysql and get output ??

please note : I installed mysql from source .. not by yum or  apt-get .

thanks for your help
Question by:fosiul01
  • 4
  • 3
LVL 81

Accepted Solution

arnold earned 2000 total points
ID: 37823649
The start is a script and not the binary file as the error says.

gdb --exec="/opt/mysql/mysqlserver5/bin/mysqld_safe --user=mysql "

alternatively you can attach to an existing process
strace -f -p <pid_of_process>

what output are you looking to get?

What are you trying to troubleshoot?
LVL 29

Author Comment

ID: 37824139
i am just trying to get use of gdb ..
as i am seeing too much semaphore although they are not too bad .. just want to try out those technique so that in bad time, i know what to do ..

just woundering if you can help me with a thread ..

bellow is a semaphore :
OS WAIT ARRAY INFO: reservation count 2437436, signal count 4990922
--Thread 139822454851328 has waited at btr0cur.c line 530 for 0.00 seconds the semaphore:
S-lock on RW-latch at 0xba80ea8 created in file dict0dict.c line 1723
a writer (thread id 139822417102592) has reserved it in mode  exclusive
number of readers 0, waiters flag 1, lock_word: 0
Last time read locked in file btr0cur.c line 530
Last time write locked in file /pb2/build/sb_0-5135321-1330717714.3/mysql-5.5.22/storage/innobase/btr/btr0cur.c line 523
Mutex spin waits 94388014, rounds 305573911, OS waits 1007616
RW-shared spins 3401896, rounds 48858411, OS waits 812488
RW-excl spins 3000245, rounds 24922097, OS waits 356572
Spin rounds per wait: 3.24 mutex, 14.36 RW-shared, 8.31 RW-excl

now the thread :
-Thread 139822454851328

i dont understand, which thread id its refering to  ...

is there any way to find out which mysql thread is refering to ??

currently only process runnign 109 and 126

but how doyou know  139822454851328 which mysql thread is refering to ??

LVL 81

Expert Comment

ID: 37824340
If you are lookin at fine tunning mysql, install myphpadmin from myphpadmin.net and look at the query performance.

dbg would usually be used to debug core dumps or failing programs.

It looks to me like a resource contention with a process that locked and is taking its time to process the data
a writer (thread id 139822417102592) has reserved it in mode  exclusive
number of readers 0, waiters flag 1, lock_word: 0


Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 29

Author Comment

ID: 37824395

i think i will be able to get that one from events_wait table..
but  those semaphore only staying for 0.00 seconds its hard to capture them.. ( in production i would of ignore those as they are not long wait..)
but i am producing those by script..so i want to  know .. from where those threads comming from ..

i meant, which mysql process is related to those threads
those threads are not mysql threads .. that definate.. but they are some how related to mysql_thread..
which i am trying to undestand ...how to find out which mysql thread is related to those threads ..
LVL 81

Expert Comment

ID: 37824908
You are going into the root seller to see where/how your guests are going/moving on the second floor.

Improving performance or diagnosing slow responses from the mysql server does not require going into the underbelly which is what dbg does.

dbg/strace is a way to determine what/where things are going wrong but you have to know what the process is more specifically your own code that generates an unexpected response to a specific input and you want to determine why.
LVL 29

Author Comment

ID: 37824953
You are going into the root seller to see where/how your guests are going/moving on the second floor.  : lol , yes it over kill!! i agree ..

but tel me something ..
the semaphore example i provided...

tel me, how will  you know which mysql  process is causing the semaphore ??

only clue is the thread Id , but how will you know which which process is related to threadid ??

with mysql 5.0 ( it showd the mysql thread id) but mysql 5.5 .. they dont show the mysql threadid .. they give a long number .which is OS thread id ..

so thats why some people is telling, you need to use gdb to find out what that thread is doing ..
LVL 81

Expert Comment

ID: 37824996
Not sure, did not see a need to such an indepth look of a functioning app.

You have to have the trace from the beginning. and then trace it back.
Not a linux/unix but is a good discussion that could help in providing overview.

Presumably the issue will depend on where the semaphore is being handled i.e. whether it is an application internal event or whether it is part of the IPC to the kernel subsystem which this one seems to be either a cache lock on a table.

have not seen a need to delve that deep to look at the operation of a running app.
usually use strace to see what is going on if a failure is occurring.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question