I check mysql server status by ssh to the server.

$ mysql
mysql> status

Beside this way, is there any other way that I can use ssh to remote check the status? Since there are many mysql servers, I don't want to ssh to each of them. Thanks.


Try mysqladmin, which can query the database for it's status.

On the localhost, you can store the password in a ~/.my.cnf file (make sure the permissions are strict). Here's an example from the MySQL 5.1 manual:

# The following password will be sent to all standard MySQL clients

Then, you can automatically query the remote MySQL server like this:

mysqladmin --host=db1.example.org --user=admin status
Uptime: 884637  Threads: 1  Questions: 5534424  Slow queries: 144  Opens: 4444  Flush tables: 21  Open tables: 166  Queries per second avg: 6.259

You'll want to make sure that the firewall on the remote server allows these connections. You'll also want to check that the MySQL privileges allow this sort of access from a remote host. If you are concerned about packet sniffing on your LAN, then configure MySQL to use SSL.

You can avoid these hassles by running the command through ssh.

ssh db1.example.org "mysqladmin status"
| improve this answer | |

You can combine it into one command:

ssh server 'echo status|mysql'

Beyond that, I would look at tools like puppet if you want further automation.

| improve this answer | |
  • This doesn't work for me. I got 'bash: mysql: command not found' error. – Stan Sep 21 '10 at 0:06
  • 1
    @Stan, that means mysql isn't in the PATH. You can adjust that, or get the full mysql path from which then put it in the command: ssh server 'echo status|/full/path/to/mysql' – Matthew Flaschen Sep 21 '10 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.