我有以下命令,我从命令行使用它来导入 mysql 备份 -
mysql -hlocalhost -uroot -pmysql dpfinal < /home/kshitiz/Desktop/dbdump.sql
当我从命令行调用此命令时,它运行良好。但是当我使用以下 Java 代码时它不起作用 -
String command = "mysql -hlocalhost -uroot -pmysql dpfinal < /home/kshitiz/Desktop/dbdump.sql";
InputStream is = Runtime.getRuntime().exec(command).getInputStream();
InputStreamReader ir = new InputStreamReader(is);
BufferedReader br = new BufferedReader(ir);
String s = br.readLine();
while(s!= null) {
System.out.println(s);
s = br.readLine();
}
我得到以下输出 -
mysql Ver 14.14 Distrib 5.5.28, for debian-linux-gnu (i686) using readline 6.2
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
--auto-rehash Enable automatic rehashing. One doesn't need to use
'rehash' to get table and field completion, but startup
and reconnecting may take a longer time. Disable with
--disable-auto-rehash.
(Defaults to on; use --skip-auto-rehash to disable.)
-A, --no-auto-rehash
No automatic rehashing. One has to use 'rehash' to get
table and field completion. This gives a quicker start of
mysql and disables rehashing on reconnect.
--auto-vertical-output
Automatically switch to vertical output mode if the
result is wider than the terminal width.
-B, --batch Don't use history file. Disable interactive behavior.
(Enables --silent.)
--character-sets-dir=name
Directory for character set files.
--column-type-info Display column type information.