In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you how to back up the MySQL database in Java, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Import java.io.File;import java.io.IOException / * MySQL database backup * * @ author GaoHuanjie * / public class MySQLDatabaseBackup {/ * Java code to export MySQL database * * @ author GaoHuanjie * @ param hostIP MySQL database server address IP * @ param userName user name * @ param password entry required to enter the database According to the password required by the library * @ param savePath database export file save path * @ param fileName database export file name * @ param databaseName database name to be exported * @ return returns true to indicate that the export is successful Otherwise, false is returned. * / public static boolean exportDatabaseTool (String hostIP, String userName, String password, String savePath, String fileName, String databaseName) {File saveFile = new File (savePath); if (! saveFile.exists ()) {/ / if saveFile.mkdirs () does not exist in the directory / / create a folder} if (! savePath.endsWith (File.separator)) {savePath = savePath + File.separator;} StringBuilder stringBuilder = new StringBuilder (); stringBuilder.append ("mysqldump"). Append ("- opt"). Append ("- h") .append (hostIP) StringBuilder.append ("--user=") .append (userName) .append ("--password=") .append (password) .append ("--lock-all-tables=true"); stringBuilder.append ("--result-file=") .append (savePath + fileName) .append ("--default-character-set=utf8") .append (databaseName) Try {Process process = Runtime.getRuntime () .exec (stringBuilder.toString ()); if (process.waitFor () = = 0) {/ / 0 indicates that the thread terminates normally. Return true;}} catch (IOException e) {e.printStackTrace ();} catch (InterruptedException e) {e.printStackTrace ();} return false } public static void main (String [] args) throws InterruptedException {if (exportDatabaseTool ("172.16.0.127", "root", "123456", "D:/backupDatabase", "2014-10-14.sql", "test") {System.out.println ("Database backup successful!") ;} else {System.out.println ("Database backup failed!") The above content is how to back up the MySQL database in Java. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.