or123456
or123456

Reputation: 2199

How to Restore backup file(mysql) with java?

I have a java project and placed sql file(backup) in this project.
how to Restore this file inside library to mysql with java(Restore of jar file)?

Upvotes: 0

Views: 890

Answers (2)

AlexR
AlexR

Reputation: 115328

Run mysql -uUSERNAME -pPASWORD SCHEMA <yourfile.sql. You can use either Runtime.getRuntime().exec() or ProcessBuilder to execute external program.

The mysql command requires redirect to restore data. You can either create shell script/batch file (depending on your operating system) and run it from java or run command line like cmd /c mysql... or /bin/sh mysql directly from java application (again, depending on your OS)

Upvotes: 0

davidethell
davidethell

Reputation: 12018

Is this against a remote server? If you are not opposed to combining Java with the MySQL command line client then you can just do:

Runtime.getRuntime().exec("/usr/bin/mysql <your connection options> < your_sql_backup.sql");

If you want it all native Java then you'll end up needing to parse your sql backup and execute the queries through JDBC.

Upvotes: 1

Related Questions