Click here to Skip to main content
15,887,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I find and print a mysql pid file using C++ code?
Posted
Updated 3-May-11 1:28am
v3
Comments
Sandeep Mewara 1-May-11 4:07am    
Any effort?
soumava chakraborty 1-May-11 4:14am    
yes sir,,I am giving my best to do this.I have got the success to connect mysql database through a c program.can you help me in this case??thanks for your concern..

The name of the PID file is stored in the MySQL global system variable pid_file. Use one of the available database APIs to query the variable value, then use the normal C++ file classes to open and read the file.
 
Share this answer
 
1. Find out where the file is stored.
2. Decode the contents of the file.
3. Print the results.
 
Share this answer
 
How about that: If the name of the environment variable is pid_file use GetEnvironmentVariable() function to acquire the corresponding value where suppose to be path to the file, and then print it out.
Here is the reference GetEnvironmentVariable() and there are samples to use Changing Environment Variables.
Sergey Chepurin.
 
Share this answer
 
v4
Comments
markkuk 1-May-11 14:04pm    
It's not an environment variable, it's a MySQL internal system variable.
Sergey Chepurin 2-May-11 2:04am    
Then, if you manage to find config (option) file such as my.cnf or mysql.server file you can try to parse it looking for pid_file lines. At least that is what other people do sometimes. Take a look on that code and corresponding files.
Sergey Chepurin.
Under Windows, the PID file for MySQL is located the same place where database root folder is.

In My.ini file:
MSIL
#Path to the database root
datadir="C:/ProgramData/MySQL/MySQL Server 5.1/Data/"


Under this path, there is a .PID file, that holds the current process id. The filename is the name of the computer.
But if you what to control is MySQL is running or not. Then use the "SC" command tool under Windows.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900