当前位置:网站首页>MySQL backup and restore command
MySQL backup and restore command
2022-06-26 10:42:00 【MervynLammm】
Mysql Backup and restore commands
- Backup command :
mysqldump -h127.0.0.1 -P3306 -uroot -p123456 mytable > mytable.sql
- Restore command :
mysql -h127.0.0.1 -P3306 -uroot -p123456 mytable < mytable.sql
-h
host -P
port -u
user name -p
password mytable
Libraries that need to be backed up mytable.sql
Backup file name
Java Realization
// Backup
public void backup() {
String[] execCMD = {
"mysqldump", "-h",+hostname, "-P"+ port, "-u"+user, "-p"+password, databaseName, ">", filename};
try {
Runtime.getRuntime().exec(execCMD);
} catch(Exception e) {
e.printStackTrace();
}
}
// recovery
public void restore() {
String[] execCMD = {
"mysql", "-h",+hostname, "-P"+ port, "-u"+user, "-p"+password, databaseName, "<", filename};
try {
Runtime.getRuntime().exec(execCMD);
} catch(Exception e) {
e.printStackTrace();
}
}
windows The system is in exceCMD Add in front "cmd","/c"
In this way, the files I backed up 0 byte . I don't know why . See the solution below .
// recovery
public void backup() {
String[] execCMD = {
"bash", "./backupSql.sh", hostname,
port, user, password, databaseName, filename};
try {
Runtime.getRuntime().exec(execCMD);
} catch(Exception e) {
e.printStackTrace();
}
}
public void restore() {
String[] execCMD = {
"bash", "./restoreSql.sh", hostname,
port, user, password, databaseName, filename};
try {
Runtime.getRuntime().exec(execCMD);
} catch(Exception e) {
e.printStackTrace();
}
}
Script files backupSql.sh
mysqldump -h"$1" -P"$2" -u"$3" -p"$4" "$5" > "$6"
Script files restoreSql.sh
mysql -h"$1" -P"$2" -u"$3" -p"$4" "$5" < "$6"
边栏推荐
- Global and Chinese markets in hair conditioner 2022-2028: Research Report on technology, participants, trends, market size and share
- 瑞萨电子面向物联网应用推出完整的智能传感器解决方案
- Global and Chinese market for change and configuration management software 2022-2028: Research Report on technology, participants, trends, market size and share
- Idea remote debugger
- OpenCV图像处理-灰度处理
- Small example of SSM project, detailed tutorial of SSM integration
- Basic string operations in C
- SSH, SCP command appears permission denied, please try again solution
- Flutter and native communication (Part 1)
- Notes - simple but adequate series_ KVM quick start
猜你喜欢
随机推荐
Linux下安装Mysql【详细】
SwiftUI 开发经验之为离线优先的应用程序设计数据层
Function run time
Introduction to libmagic
JVM的符号引用和直接引用是什么
工程数学概率论统计简明教程第二版复习大纲
开发者,微服务架构到底是什么?
Vscode environment setup: synchronous configuration
8- creating leecode algorithm with pictures and texts - algorithm solution of minimum stack and LRU caching mechanism
Postman入门教程
Flutter and native communication (Part 1)
How to start the learning journey of webrtc native cross platform development?
挖财商学院证券开户安全嘛?
MySQL项目7总结
Write data to local file
MySQL 9th job - connection Query & sub query
利用foreach循环二维数组
CentOS installs redis multi master multi slave cluster
MySQL第八次作业
SQL Server foundation introduction collation