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

We are running a couple of shared host linux servers and a private one. We are running cPanel/WHM licenses under them.

The predicament I am facing is :

How can I run the following command automatically ?

mysqlcheck -u root -p --auto-repair --check --optimize --all-databases

The problem is that I am prompted for the root password, but I would like to run this command automatically and the password prompt intrerupts this process.

Please help me.

share|improve this question

3 Answers 3

up vote 0 down vote accepted

You could just supply the password on the commandline. Of course this has some privacy/security issues.

mysqlcheck -uroot -pPASSWORD --auto-repair --check --optimize --all-databases
share|improve this answer

You could put the required password either in the [client] section of your ~/.my.cnf or an additional config file you specify with --defaults-extra-file=path/to/yourconfig.cnf

For more details, please refer to the option-files segment of the MySQL documentation.

share|improve this answer
    
Thank you so much, Sven. –  andrei.troll Oct 25 '12 at 7:08

Store your root credentials in a file that only the root user can access. Then simply pass the credentials filename.

mysqlcheck --defaults-file=/etc/mysql/root.cnf  --auto-repair --check --optimize --all-databases

/etc/mysql/root.cnf

[client]
host     = servername.domain.tld
user     = backup
password = strongpassword

This doesn't create a huge security vulnerability so long as /etc/mysql/root.cnf is only readable by root since the root user could easily reset the mysql passwords without needing any mysql credentials at all.

share|improve this answer
    
Thank you, Zore. –  andrei.troll Oct 25 '12 at 7:09

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.