The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do you backup mysql from cron without exposing the password

Discussion in 'General Discussion' started by dwh2, Feb 28, 2006.

  1. dwh2

    dwh2 Well-Known Member

    Joined:
    Jan 14, 2004
    Messages:
    106
    Likes Received:
    0
    Trophy Points:
    16
    I don't even remember setting this up but I get an email for every cron that runs as root. One of those crons backs up my sql database. And it sends my password through email as well as getting sent in the logwatch emails. How can I run this command without putting the password in the cron in a visible way?

    Code:
     /usr/local/bin/mysqldump --opt -Q -uusername -ppassword databasename |gzip >filename.gz
    
     
  2. elleryjh

    elleryjh Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    479
    Likes Received:
    0
    Trophy Points:
    16
    If it's running as root, you shouldn't need to include a username or password.

    Just use
    Code:
     /usr/local/bin/mysqldump --opt -Q databasename |gzip >filename.gz
     
  3. dwh2

    dwh2 Well-Known Member

    Joined:
    Jan 14, 2004
    Messages:
    106
    Likes Received:
    0
    Trophy Points:
    16
    Thanks for the reply!
    Just tried that on the command line but got this error:

    /usr/local/bin/mysqldump: Got error: 1045: Access denied for user: 'root@localhost' (Using password: NO) when trying to connect
     
  4. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    Check for the file /root/my.cnf - this would normally contain the MySQL root password removing the need to enter it.

    The file should contain the following entry:

    Code:
    [client]
    user=root
    pass=rootpasswordhere
    If it's missing, create it. It should have ownership root:root and permissions 0600.
     
  5. dwh2

    dwh2 Well-Known Member

    Joined:
    Jan 14, 2004
    Messages:
    106
    Likes Received:
    0
    Trophy Points:
    16
    Thank you!
    That is very informative.
     
Loading...

Share This Page