Search code examples
mysqlmysqladmin

"service mysql reload" mysqladmin: connect to server at 'localhost' failed BUT restart works fine


Reload'ing mysql fails. But both restart and status work fine.

Any ideas on how to fix/troubleshoot so reload works?

On restart it also takes about 20 seconds to restart like something is timing out before it finishes. I tried creating a local .my.cnf to root thinking its a password issue for "mysqladmin" but same result.

Other items that I think might be related. "skip-name-resolve" was enabled and in doing so mysql error log mentioned could not resolve localhost from entrys in "mysql" table for user and db tables so changed all "localhost" entries to 127.0.0.1

Error log said:

"[Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode."

Result of reload:

# sudo service mysql reload
* Reloading MySQL database server mysqld                                                                                                                                                                                                                           
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!

Solution

  • mysqladmin could not find the .sock file so I made a symlink to it but on mysql restart my symlink was deleted. I updated my my.cnf and commented out the path to the .sock file so that it uses the default location instead. Here is how i figured it out.

    # mysqladmin version
    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!
    
    # grep "sock" /etc/mysql/my.cnf
    socket                         = /var/lib/mysql/mysql.sock
    socket                         = /var/lib/mysql/mysql.sock
    
    # mysqladmin --socket=/var/lib/mysql/mysql.sock version
    mysqladmin  Ver 8.42 Distrib 5.7.22, for Linux on x86_64
    
    # ln -s /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock 
    
    # mysqladmin version
    mysqladmin  Ver 8.42 Distrib 5.7.22, for Linux on x86_64
    

    This only worked until a restart deleted the .sock so made sure my config was using the default location for it instead.

    # vi /etc/mysql/my.cnf
    #socket                         = /var/lib/mysql/mysql.sock
    # service mysql restart