Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there an effective way to check max_used_connections in mysql without logging into the server.As i need to get the result using watch command.

currently we are manually logging into the mysql server and checking "show status like '%max_used%';" But can it be performed using watch command???? or any other method to automate this...

share|improve this question
add comment

1 Answer

The "mysql" command and the "mysqladmin" command could both be used to produce this output with a one-liner, but in both cases they're going to prompt you for login credentials, which is I assume what's biting you. The thing to do in this case is to make use of the ~/.my.cnf file containing the appropriate information to automatically log you in -- both mysql and mysqladmin will utilize the credentials found in ~/.my.cnf if it exists.

As the user you want to run the "watch" command with, type "vim ~/.my.cnf" or "nano ~/.my.cnf", whichever editor you prefer, and if it doesn't exist or if it does exist, make it look like this:

[client]
user = USERNAME
password = PASSWORD
host = HOSTNAME

USERNAME is the MySQL user you want (could be root if that's what you want), PASSWORD is that user's password, and HOSTNAME is the hostname (if you're on the MySQL box, this is "localhost" w/o the quotes).

If you set up ~/my.cnf properly, it will be noticed by 'mysql' and 'mysqladmin' binaries and used to login if you don't specify a different user or password request with '-u' and '-p' options.

share|improve this answer
    
Oh and bear in mind this is a potential security risk. Be sure to set permissions on ~/.my.cnf to prevent access by unauthorized users, OR create a user in MySQL that only has the minimum privileges required to get what you want and make that the username you have in this file. –  Nex7 Mar 20 '12 at 7:11
    
Now it is not asking for login but still i dont know how to execute show status like max_used in a single line using mysql command or mysqadmin...Can u please halp me in it... –  Newbie Mar 20 '12 at 7:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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