Click here to Skip to main content
13,289,335 members (56,979 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


20 bookmarked
Posted 21 Jan 2009

Monitoring a MySQL Server Process

, 26 Oct 2010
Rate this:
Please Sign up or sign in to vote.
An example of monitoring a Windows process


This article is an example of monitoring a process. It will look for a running process and can start and stop the process, too.


If you are using MySQL 5 as a database server, you already know that there are no icons that show whether the server is running or not. You can look at the task manager, but perhaps you want to shutdown the server because the development session is over and the server uses so much memory (about 50 MB). If you installed the server as a service, you can stop the service, but you must have administrator privileges. If MySQL is not run as a service, you can execute a program to start and stop the server and this article contains the code to easily do that.

Using the code

To use this code, you need the MySQL server software that can be downloaded from[^], but in reality, any software will do. This just an example.

The program works by monitoring the existence of a running process that you can check with the Windows Task Manager.


As shown in the figure, the MySQL server process is named mysqld.exe. To monitor the process, this code is executed periodically with a Timer event as follows:

private void timer1_Tick(object sender, EventArgs e)
    Process[] server =  Process.GetProcessesByName("mysqld");            
    if (server.Length != 0)
        bool stat = true;
        //check if current status same as previous. this prevent notification always shown
        if (serverStat != stat) 
            OnRaiseServerEvent(new serverEventArgs(true)); //raise server event
            serverStat = stat;
        bool stat = false ;
        //check if current status same as previous. this prevent notification always shown
        if (serverStat != stat) 
            OnRaiseServerEvent(new serverEventArgs(false)); //raise server event
            serverStat = stat; //update global status

Starting the server is easy; just execute mysqld.exe and it's done. Unfortunately you can't simply stop the process to shutdown the server. Well, it could be done, but an internal error might occur inside the server. To stop the server, you should instead execute: mysqladmin.exe --user=root shutdown.

To start the server:

FileInfo fi = new FileInfo(appPath + "\\mysqld.exe");
if (fi.Exists)
    errorProvider1.SetError(txtPath, "this isn't mysql installation directory");

Similarly, to stop the server:

FileInfo fi = new FileInfo (appPath + "\\mysqladmin.exe");
if (fi.Exists)
    Process.Start(fi.FullName, "--user=root shutdown");
    errorProvider1.SetError(txtPath, "this isn't mysql installation directory");

Points of Interest

This code is useful if you are running MySQL server. You can start and stop the server by clicking a button, rather than by typing from a command prompt. You can also click on a button installed in the system tray as shown in the following image.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Engineer Donatus Inc.
Indonesia Indonesia
I'm currently a student of Brawijaya University. I work on programming just for hobby. I learn programming since 2nd year of my college. That's when I first bought my PC on year 2004.

You may also be interested in...


Comments and Discussions

BugAcess starttime error Pin
Chrosxz1-Feb-13 1:08
memberChrosxz1-Feb-13 1:08 
QuestionPassing parameter Pin
Chrosxz27-Jan-13 18:23
memberChrosxz27-Jan-13 18:23 
QuestionNeed VB.Net Version Pin
Chrosxz25-Jan-13 22:26
memberChrosxz25-Jan-13 22:26 
GeneralMy vote of 5 Pin
darkfr3ak8-Nov-11 9:49
memberdarkfr3ak8-Nov-11 9:49 
Really nice and simple Smile | :) Thanks for this.
GeneralPath Pin
Niemand2527-Jan-09 5:28
memberNiemand2527-Jan-09 5:28 
GeneralRe: Path Pin
asugix3-Feb-09 20:42
memberasugix3-Feb-09 20:42 
GeneralNice Article Pin
Syed M Hussain21-Jan-09 10:54
memberSyed M Hussain21-Jan-09 10:54 
AnswerRe: Nice Article Pin
asugix21-Jan-09 19:06
memberasugix21-Jan-09 19:06 
GeneralMy vote of 1 Pin
karabax21-Jan-09 7:15
memberkarabax21-Jan-09 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 26 Oct 2010
Article Copyright 2009 by asugix
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid