代码段:
.....
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("mysqldump -uroot -p123456 --host=localhost --port=3306 --skip-tz-utc -q --opt --no-autocommit -tc --where=\"id IN(1,2,3)\" database table");
.....运行这个命令为什么总会报错呢?
mysqldump: Got error: 1049: Unknown database 'IN(1,2,3)"' when selecting the database在命令行直接运行这个命令是没有问题的,并且在windows下运行也是没有问题的,但要linux下就会报错,到底是什么问题?谢谢
错误是:mysqldump: Got error: 1049: Unknown database 'IN(1,2,3)"' when selecting the database 它是把--where里面的条件当成了数据库名啊怎么会这样的?要怎么写才正确啊?真郁闷
使用单引号试试。
runtime.exec("mysqldump -uroot -p123456 --host=localhost --port=3306 --skip-tz-utc -q --opt --no-autocommit -tc --where=\'id IN(1,2,3)\' database table");
把表的名字用[]括起来看看。
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("test.txt"), "utf8"));用这种方式读就可以指定编码,指定的编码与文件的编码一致,应该不会有乱码的
改成这样的话错误是:mysqldump: Got error: 1049: Unknown database 'OR' when selecting the database好像是把--where后面的第一个空格之后的当成了数据库名
where=\"id=1\"试试,看是不是因为不认识in或or等关键字。