cantsay
cantsay

Reputation: 2046

Using mysqli_connect to check if an MySQL is running without credentials?

I need to check if MySQL is running in a PHP script, so I thought about using mysqli_connect

The only problem is, I don't want it to require MySQL login details. Is it possible to log in without an account? If I log in with no password, or a made up username and password, does the "access denied" prove that MySQL is running?

Is there a better way to do this? If not, what MySQL permissions can I give to an account so I can log in but can't do anything?

Upvotes: 1

Views: 147

Answers (2)

Digital Chris
Digital Chris

Reputation: 6202

I think what you're looking for is

mysqladmin ping

Check whether the server is available. The return status from mysqladmin is 0 if the server is running, 1 if it is not. This is 0 even in case of an error such as Access denied, because this means that the server is running but refused the connection, which is different from the server not running.

You can run this from php, or direcly in a cron job and test for 0.

Upvotes: 0

xate
xate

Reputation: 6379

You will receive a "DB Exception" when you address a database, which is not existing, deactivated or whatever.

Access Denied provides, that MySQL is running - checked your username and password and gave a response.

Access Denied = Database up - you are right!

Upvotes: 1

Related Questions