Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysqladmin ping error code

Mysqladmin ping returns 0 even with a password failure, a thing that mysqlclient doesn't. Is this a mistake from Mysqladmin Developpers? I don't understand why Mysqladmin is asking for a login/password because it returns 0 even if you don't specify a login.

If I try a Mysqladmin ping without any login/password :

# mysqladmin ping ; echo $?

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
0

Mysqladmin give me a login error and tells me that the server is currently running (0 value) so why asking for a login if it still gives me the answer?


When I do something like this :

#mysqladmin -uroot -pWrongPassword ping ; echo $?

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
0

This return me 0 instead of 1.


Now if I stop mysql server and try again :

# mysqladmin -uroot -pWrongPassword ping ; echo $?

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
1

It gives me the proper value because the server is stopped, we dont care about the wrong password.


Finally i did the same test with Mysqlclient and a wrongpassword :

# mysql -uroot -pWrongPassword mysql -sN -e "select * from user" ; echo $?

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
1

I know that the main purpose of this command is to test the availability of the mysql server but ask for a login/password doesn't make any sense if you still give the 0 value.

Do you think it is a bug?

like image 594
Arka Avatar asked Aug 30 '13 00:08

Arka


1 Answers

It's not a bug. This behavior is by design.

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.

like image 177
peterm Avatar answered Nov 20 '22 09:11

peterm