PDA

View Full Version : mysqldump problems


marshalleto
02-05-02, 14:14
Hi I am a novice Mysql user.

I can use the mysqldump utitlity just fine on the command line to make a backup of my sql tables, but when I try to call it from a script I get a "Access denied for user: 'root@localhost' (Using password: YES)" error. What gives?

my perl script which tries using the mysqldump utility looks like this:
---------------------------------------------
#!/usr/bin/perl

system ("mysqldump -u root -p=password -c --add-drop-table db_name > db_dump.dump");

----------------------------------------------

When I try to execute the script from the command line or from CRON, I get the access denied error.
But if I just type the same command on the command line it works great.

Any help would be greatly appreciated. THANKS!!

hakon
02-06-02, 07:53
I consider it a bad idea to write passwords on command-lines, since anyone who's logged in can see the password by `ps aux` or something similar. However, if you insist on doing it this way, the correct syntax would be `mysqldump -pPASSWORD`. Notice how there is no space between the '-p' and the actual password. You could also do '--password=PASSWORD' if you think it looks better.

In my opinion, though, the right way of doing this would be to have a file called .my.cnf on root's home directory containing at least the following lines:

[mysqldump]

user = root

password = PASSWD

and then invoke mysqldump with just a '-p'. Safer and more elegant.

marshalleto
02-06-02, 09:58
Thanks Hakon! My script works great now. I still don't know why it didn't work before; but who cares.