how to debug mysql with gdb .

Posted on 2012-04-09
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 78

Accepted Solution

arnold earned 500 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 78

Expert Comment

ID: 37824340
If you are lookin at fine tunning mysql, install myphpadmin from 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
Industry Leaders: 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 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 to find out which mysql thread is related to those threads ..
LVL 78

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 78

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php56-php-mcrypt for rhel7 php56 1 98
Where on a calculated field 1 29
Ubuntu don’t allow SU command in terminal 7 54
Understanding ping command in Ubuntu 5 28
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Fine Tune your automatic Updates for Ubuntu / Debian
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

680 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