1

I've seen this work with local MySQL databases:

Runtime.getRuntime().exec("mysqldump -u USERNAME -p PASSWORD DBNAME > /path/to/location/backup.sql");

But is it possible to dump a remote MySQL database from a web server?

I'm making a program that backs up both my website files via FTP (already done with this part), and backs up my MySQL databases on the server as well. Therefore I need to know how to do this.

2 Answers 2

1

if you are trying to dump your database data from other computer you'll need to grand privileges to an specific user for this task.

for example, the user is: 'remoteAdminUser'

GRANT SELECT, LOCK TABLES 
ON *.* 
TO 'remoteAdminUser'@'localhost' IDENTIFIED BY 'dbPass';

and then you can use this java code

/******************************************************/
//Database Properties
/******************************************************/
String dbName = “dbName”;
String dbUser = “remoteAdminUser”;
String dbPass = “dbPass”;
String filePath = “c:\\sqlDump\myFirstDump.sql”;
/***********************************************************/
// Execute Shell Command
/***********************************************************/
String executeCmd = "";
executeCmd = "mysqldump -u "+dbUser + " -p"+dbPass + " "+dbName + " -r "+filePath;
}
Process runtimeProcess =Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if(processComplete == 0){
out.println("Backup taken successfully");
} else {
out.println("Could not take mysql backup");
}
Sign up to request clarification or add additional context in comments.

3 Comments

No, i am trying to dump it from a webserver, which means the MySQL server is on a domain.
Ok, but let me know if you can query that database from the webServer, for example, can you do a "select * from information_schema.tables"
So it means you must have MySQL installed in your local machine to use mysqldump, it is also not the best way, is there or not the to dump the database directly from Java using some protocols?
0

It can be done if you have access to the server. You can tell mysqldump to connect to a remote server:

mysqldump -h yourServerAddress -u yourUser -pYourPassword dbName > output_file.sql

yourServerAddress is the IP address where the MySQL server is.

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.