LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-13-2006, 11:47 AM   #1
Seventh
Member
 
Registered: Dec 2003
Location: Boston, MA
Distribution: Redhat / Debian
Posts: 269

Rep: Reputation: 30
MySQL shell usage question / cron script


I believe this is the right forum for this, I hope so.

I'm trying to automate a mysqldump backup of a database on my server running FC2. I'm reading the man pages, but I'm a tad confused.

I'm trying to setup a script in cron.weekly that will simply backup my DB to a file in /home/backups

Right now I have:

mysqldump --opt -Q -u dbusername -p databasename > backup.sql

This runs just fine, but asks me for a password. In the man page, it lists --p for the password option.

However when I try to run it as:

sqldump --opt -Q -u dbusername -p databasename --p my password > backup.sql

It still prompts me for a password. *scratches head*

So two questions really,

A) What's the proper syntax for a completely automated script?
B) Is there a way that I can change up the filename dynamically based on the date?

Thanks much!
 
Old 01-13-2006, 02:12 PM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
uhm, the answer to the password question may be to use the password param like so..

Code:
--password='the_password'
 
Old 01-13-2006, 02:34 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
Using a password on the command line is a little bit insecure. Better not to get that habit. Instead you can create a file called ".my.cnf" in your home directory containing:
Code:
[client]
user = seventh
password = secret
(obviously you should replace "seventh" and "secret" with your mysql username and password)

Also make sure the file has permissions set to 600 (-rw-------). The file will be read by the mysql client programs (including "mysqldump") to get a username and password automatically.

Last edited by Hko; 01-13-2006 at 02:37 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 09:09 AM
run shell script on cron varunbihani Linux - Newbie 5 07-08-2005 02:50 AM
shell script? : usage of $! with su -c option DTParanoia Linux - General 3 04-05-2005 06:58 PM
shell script fo run auto job in cron JolynnMarie LinuxQuestions.org Member Intro 0 04-28-2004 12:21 PM
Mysql Cron Script using select not working fallen Linux - General 2 11-04-2003 08:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration