SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How to kill a MySQL process?

    Hello,

    How do I find which mysql process has crashed, or is stuck and not running to completion, and then how to KILL it?

    FYI, if via mytop I see that process ID 2987 has been running for 78000
    seconds, I am assuming that this process has crashed. Then how to kill it?

    Regards,

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,268
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    I don't know if this will help, but in my localhost XAMPP, the xampp_stop.exe file runs the mysql_stop.bat file which is
    Code:
    @echo off
    echo Mysql shutdowm ...
    mysql\bin\mysqladmin --user=pma --password= shutdown

  3. #3
    SitePoint Zealot j3ph's Avatar
    Join Date
    Jan 2006
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What operating system?

  4. #4
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I do not want to Stop MySQL, but just to find what MySQL processes have crashed and KILL it specifically.

    Regards,

    Quote Originally Posted by Mittineague View Post
    I don't know if this will help, but in my localhost XAMPP, the xampp_stop.exe file runs the mysql_stop.bat file which is
    Code:
    @echo off
    echo Mysql shutdowm ...
    mysql\bin\mysqladmin --user=pma --password= shutdown

    Anoox search engine volunteer

    www.anoox.com

  5. #5
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    The operating system is Linux, Red Hat Enterprise.
    Web server is Apache.

    Regards,

    Quote Originally Posted by j3ph View Post
    What operating system?

    Anoox search engine volunteer

    www.anoox.com

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,268
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Maybe something like this (or the class) from http://dev.mysql.com/doc/refman/5.1/en/kill.html
    PHP Code:
    $result mysql_query("SHOW FULL PROCESSLIST");
    while (
    $row=mysql_fetch_array($result)) {
    $process_id=$row["Id"];
    if (
    $row["Time"] > 200 ) {
    $sql="KILL $process_id";
    mysql_query($sql);
    }


  7. #7
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for this code.
    Actually this is a very useful/good PHP code.

    But I am just looking for the exact MySQL or Linux command to do this
    job from either the MySQL client or the Linux command line.

    Regards,

    Quote Originally Posted by Mittineague View Post
    Maybe something like this (or the class) from http://dev.mysql.com/doc/refman/5.1/en/kill.html
    PHP Code:
    $result mysql_query("SHOW FULL PROCESSLIST");
    while (
    $row=mysql_fetch_array($result)) {
    $process_id=$row["Id"];
    if (
    $row["Time"] > 200 ) {
    $sql="KILL $process_id";
    mysql_query($sql);
    }


    Anoox search engine volunteer

    www.anoox.com

  8. #8
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    kill connection process_id

  9. #9
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Bu my question was how do I find out which MySQL process_id to kill
    without logging into MySQL, but just being logged into the server via SSH.

    Quote Originally Posted by al-zabir View Post
    kill connection process_id

    Anoox search engine volunteer

    www.anoox.com

  10. #10
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do you check your regular processes that are running and know which ones have crashed? if you run your
    Code:
    ps -l
    that will give you your process list, but IIRK it doesn't suggest which is a crashed process and which isn't does it? sorry but been a while since i've worked on unix/linux box.

  11. #11
    SitePoint Zealot j3ph's Avatar
    Join Date
    Jan 2006
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might try
    ps -waux

  12. #12
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    what you're actually looking for is the SHOW PROCESS LIST and KILL commands.

    you definitely don't want to issue an OS level kill command against mysql, especially if that connection is making changes.
    Check out our new Industry News forum!
    Keep up-to-date with the latest SP news in the Community Crier

    I edit the SitePoint Podcast

  13. #13
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    982
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    mysql -h <hostname> -u <username> -p <database_name>
    SHOW PROCESSLIST;
    KILL ###;
    After the first command you will be prompted to enter your password
    After the second command you should note the process id and use that in the third command.
    Last edited by BrandonK; Jan 12, 2009 at 13:30. Reason: Removed server prompts to avoid confusion
    MySQL v5.1.58
    PHP v5.3.6


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •