how to debug mysql with gdb .

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
LVL 29
Who is Participating?
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?
fosiul01Author Commented:
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 ??

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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

fosiul01Author Commented:

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 ..
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.
fosiul01Author Commented:
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 ..
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.