java 呼叫命令列 備份mysql資料庫

2021-05-26 21:03:07 字數 1643 閱讀 4094

// 方式1

string command = "d:\\mysql\\bin\\mysqldump -h127.0.0.1 -uroot -p -ntd -r -dbname";

runtime runtime = runtime.getruntime();

process process = runtime.exec(command);

inputstreamreader reader = new inputstreamreader(process.getinputstream());

bufferedreader buffreader = new bufferedreader(reader);

string instr;

string outstr;

stringbuffer buffer = new stringbuffer();

while ((instr = buffreader.readline()) != null)

outstr = buffer.tostring();

outputstream os = new fileoutputstream("d:\\sql.sql");

outputstreamwriter writer = new outputstreamwriter(os);

writer.write(outstr);

writer.flush();

reader.close();

buffreader.close();

os.close();

writer.close();

// 方式2

string command = "cmd /c mysqldump -h127.0.0.1 -uroot -p -ntd -r -dbname";

runtime runtime = runtime.getruntime();

process process = runtime.exec(command, null,new file("d:\\mysql\\bin"));

inputstreamreader reader = new inputstreamreader(process.getinputstream());

bufferedreader buffreader = new bufferedreader(reader);

string instr;

string outstr;

stringbuffer buffer = new stringbuffer();

while ((instr = buffreader.readline()) != null)

outstr = buffer.tostring();

outputstream os = new fileoutputstream("d:\\sql.sql");

outputstreamwriter writer = new outputstreamwriter(os);

writer.write(outstr);

writer.flush();

reader.close();

buffreader.close();

os.close();

writer.close();

C 呼叫命令列

開關 c表示執行完命令就退出 system.diagnostics.process cmd system.diagnostics.process.start cmd.exe c xcopy c test1 c test2 y q s cmd.waitforexit system.diagnostic...

C 呼叫命令列

開關 c表示執行完命令就退出 system.diagnostics.process cmd system.diagnostics.process.start cmd.exe c xcopy c test1 c test2 y q s cmd.waitforexit system.diagnostic...

使用命令建立mysql 命令列建立MySQL使用者

抄自 進入mysql安裝目錄 cd usr local mysql bin 登入.mysql u root p 建立乙個使用者名稱和密碼分別為 myuser 和 mypassword 的使用者,使用者被建立後,包括加密的密碼 許可權和資源限制在內的所有帳號細節都會被儲存在乙個名為user的表中,這個...