In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces you how to achieve backup and restore in the Mysql database, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Import java.io.IOException
Import java.text.SimpleDateFormat
Import java.util.Date
Public class BackupMysql {
/ * * access the url where the MySQL server is located * /
Private String serverUrl
/ * * user name for accessing MySQL database * /
Private String username
/ * * password for accessing MySQL database * /
Private String password
Public String getServerUrl () {
Return serverUrl
}
Public void setServerUrl (String serverUrl) {
This.serverUrl = serverUrl
}
Public String getUsername () {
Return username
}
Public void setUsername (String username) {
This.username = username
}
Public String getPassword () {
Return password
}
Public void setPassword (String password) {
This.password = password
}
Public BackupMysql (String serverUrl,String username, String password) {
Super ()
This.serverUrl=serverUrl
This.username = username
This.password = password
}
Public String backup (String backupPath, String dbName) throws IOException {
String backupFile = backupPath+ dbName+ new SimpleDateFormat ("yyyy-MM-dd-HH-mm-ss") .format (new Date ()) + ".sql"
String = "mysqldump" + "--host=" + serverUrl+ "--user=" + username + "--password=" + password + "--opt" + dbName + ">" + backupFile
Java.lang.Runtime.getRuntime () .exec (cmd / c + mysql)
System.out.println ("backup successful!")
Return backupFile
}
Public void restore (String restoreFile, String dbName) throws Exception {
String mysql = "mysql" + "- h" + serverUrl+ "- u" + username + "- p" + password + "" + dbName + "<" + restoreFile
System.out.println (mysql)
Java.lang.Runtime.getRuntime () .exec (cmd / c + mysql)
System.out.println ("restore successful!")
}
/ * *
* @ param args
, /
Public static void main (String [] args) {
String serverUrl= "127.0.0.1"
String userName = "root"
String pwd = "root"
BackupMysql backup = new BackupMysql (serverUrl,userName, pwd)
Try {
Backup.restore ("d:/nationz2010-12-20-14-16-47.sql", "nationz")
} catch (Exception e) {
E.printStackTrace ()
}
}
}
On how to achieve backup and restore in the Mysql database to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.