Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 79

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 79

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


Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

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 79

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 79

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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

Fine Tune your automatic Updates for Ubuntu / Debian
In this article, we’ll look at how to deploy ProxySQL.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

730 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