1

i have to make backups of mysql database in my application.

I run the command in Windows and works nice. This is the command:

String executeCmd = mysqldumppath +" -u " + dbUserName + " -p" + dbPassword + " --add-drop-database -B " + dbName + " -r " + filePath;
Runtime.getRuntime().exec(executeCmd);

When i try this command on my linux server, i need to put a sudo password. How i pass password in the command line?

I had read many solutions but no success.

3
  • you ran it from the command line in Windows? Commented Jun 19, 2015 at 17:07
  • 2
    Have you tried executing the Java program as root? Commented Jun 19, 2015 at 17:07
  • Are you running your java code from the command line? NOT the mySQL command. I mean java MyClass. Commented Jun 19, 2015 at 17:16

2 Answers 2

2

Either run your Java program as root (with sudo) or pass the sudo password via stdin to sudo (very insecure, practically no secure way to implement this).

Sign up to request clarification or add additional context in comments.

2 Comments

I am using glassfish server wih war file deployed. Should i start glassfish with sudo command?
@VítorNóbrega That information would be useful in your question.
0

Why are you have to enter password when execute the mysqldump command use the glassfish user?

Because you just have the privilege that execute the command with a password. If you want to execute commands password-less, edit the /etc/sudoers file use visudo, put a line in the end(if you run the glassfish server use glassfish user), eg:

glassfish    ALL=(All)    NOPASSWD: mysqldumppath

You can also copy the line into a file and put it to the /etc/sudoers.d directory. Now, try execute the command use sudo again! Good luck! :-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.