Troubleshoot: mysqladmin connect to server at localhost failed

Connect to a Docker MysQL Container with mysqladmin

The most obvious reason for the "mysqladmin: connect to server at 'localhost' failed" message is that MySQL Server is not running. Following is the complete error message.

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory")'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
mysqladmin: connect to server at 'localhost' failed

Check MySQL Server Status and Start MySQL

First, check whether MySQL is running on your Linux machine.

systemctl status mysql

Or

service mysql status

If you use MariaDB, Type:

systemctl status mariadb

If Server status is not active, start the MySQL Server:

systemctl start mysql

Or

service mysql start

Connect to a Remote MySQL Host

To connect to a remote MySQL Server, you need to use -h option.

mysqladmin -u user -p -h 192.168.1.10 ping

Connect to a Docker MySQL Container

If you are trying to run the mysqladmin command on a docker container from the docker host, use the loopback address 127.0.0.1 instead of localhost.

mysqladmin -p -h 127.0.0.1  ping

If you try to connect to a mysql container through the localhost you will get the "mysqladmin: connect to server at 'localhost' failed" error message.