我有一个用java和MySQL开发的应用程序。我在局域网上使用它,并在使用Windows 7专业版x64的PC上托管该应用程序。此PC用作服务器,不用于任何其他目的。我已经共享了应用程序类文件公开驻留的文件夹,其他PC可以使用以下批处理脚本连接到此应用程序:
net use v: \\192.168.0.44\MyAppName
v:
start "" /b javaw -cp .;v:\bin;v:\lib\swt.jar;v:\lib\mysql-connector-java-5.0.8-bin.jar;v:\lib\jdatepicker-1.3.2.jar;v:\lib\commons-io-2.4.jar;v:\lib\jfreechart-1.0.17.jar;v:\lib\jcommon-1.0.21.jar;v:\lib\forms-1.3.0.jar;v:\lib\activation-1.1.jar;v:\lib\commons-email-1.3.2.jar;v:\lib\mail.jar main.Main
所有PC都在使用JAVA 7,并且正在运行Windows 7,8和Mac,全部是64位。网络电缆很大。
此应用程序的所有部分都可以正常工作,只有备份会产生问题。我使用了以下java代码:
public static boolean getDatabaseBackUp() {
boolean isSucess = false;
File dbBackUpFile = new File("db.sql");
File mysqlDir = new File("\\\\192.168.0.44\\xampp\\mysql");
File mysqlBinDir = new File(mysqlDir, "bin");
File mysqlumpFile = new File(mysqlBinDir, "mysqldump.exe");
String dbUser = "myUserName";
String dbPass = "myPassword";
String dbName = "myDbName";
String executeCmd = "";
executeCmd = mysqlumpFile + " " + dbName + " -u " + dbUser
+ " --password=" + dbPass + " " + " -r \""
+ dbBackUpFile.getAbsolutePath() + "\"";
System.out.println(executeCmd);
try {
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
System.out.println("Process is completed");
isSucess = true;
} else {
System.out.println("Process is NOT completed");
isSucess = false;
}
} catch (Exception e) {
e.printStackTrace();
isSucess = false;
}
return isSucess;
} // getDatabaseBackUp ()
以上代码用于从所有通过网络的电脑(包括服务器),当数据库小时工作正常,我的意思是大约3 MB,但现在已经有335 MB 和备份仅当您在服务器PC上打开应用程序时才能工作,当它从任何其他PC上打开时网络getDatabaseBackUp()
返回false
。
如果我使用-debug -verbose
运行它,则输出为:
\\192.168.0.44\xampp\mysql\bin\mysqldump.exe myApplication -u myUserName --password=myPassword -r "\\192.168.0.44\myApplication\assets\db_backups\2014_06_10_16_28_13.sql"
[Loaded java.lang.ProcessBuilder from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.lang.Process from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.lang.ProcessImpl from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.lang.ProcessImpl$2 from C:\Program Files\Java\jre7\lib\rt.jar]
Process is NOT completed
如果我在服务器上运行mysqldump ... --verobse ...
,我会:
C:\Users\myPcUserName>\\192.168.0.44\xampp\mysql\bin\mysqldump.exe myApplicationName -u myUserName --password=myPassword --verbose -r "\\192.168.0.44\myApplicationName\assets\db_backups\2014_06_11_09_59_56.sql
-- Connecting to localhost...
-- Retrieving table structure for table batch_fault_count...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table batch_insert_time_check...
-- It's a view, create dummy table for view
-- Retrieving table structure for table batch_status_logs...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table batch_types...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table batch_username_for_pq_check...
-- It's a view, create dummy table for view
-- Retrieving table structure for table batches...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table batches_price_list...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table dblock...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table digitally_verified_file_count...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table dvds...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table dvds_batches...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table expense_types...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table expenses...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table files...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table keys_values...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table mailing_list...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table qc_dblock...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table scanners_dirs...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table settings...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table user_check_ins...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table user_groups...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table users...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table users_salary...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving view structure for table batch_fault_count...
-- It's base table, skipped
-- Retrieving view structure for table batch_insert_time_check...
-- Retrieving view structure for table batch_status_logs...
-- It's base table, skipped
-- Retrieving view structure for table batch_types...
-- It's base table, skipped
-- Retrieving view structure for table batch_username_for_pq_check...
-- Retrieving view structure for table batches...
-- It's base table, skipped
-- Retrieving view structure for table batches_price_list...
-- It's base table, skipped
-- Retrieving view structure for table dblock...
-- It's base table, skipped
-- Retrieving view structure for table digitally_verified_file_count...
-- It's base table, skipped
-- Retrieving view structure for table dvds...
-- It's base table, skipped
-- Retrieving view structure for table dvds_batches...
-- It's base table, skipped
-- Retrieving view structure for table expense_types...
-- It's base table, skipped
-- Retrieving view structure for table expenses...
-- It's base table, skipped
-- Retrieving view structure for table files...
-- It's base table, skipped
-- Retrieving view structure for table keys_values...
-- It's base table, skipped
-- Retrieving view structure for table mailing_list...
-- It's base table, skipped
-- Retrieving view structure for table qc_dblock...
-- It's base table, skipped
-- Retrieving view structure for table scanners_dirs...
-- It's base table, skipped
-- Retrieving view structure for table settings...
-- It's base table, skipped
-- Retrieving view structure for table user_check_ins...
-- It's base table, skipped
-- Retrieving view structure for table user_groups...
-- It's base table, skipped
-- Retrieving view structure for table users...
-- It's base table, skipped
-- Retrieving view structure for table users_salary...
-- It's base table, skipped
-- Disconnecting from localhost...
C:\Users\myPcUserName>
但是如果我在其他电脑上运行mysqldump ... --verobse ...
,我会得到:
C:\Users\myPcUserName>\\192.168.0.44\xampp\mysql\bin\mysqldump.exe myApplicationName -u myUserName --password=myPassword --verbose -r "\\192.168.0.44\myApplicationName\assets\db_backups\2014_06_11_09_59_56.sql
-- Connecting to localhost...
mysqldump: Got error: 1049: Unknown database 'myApplicationName' when selecting the database
任何人都可以告诉我这是什么问题以及我可以解决它的问题吗?
答案 0 :(得分:0)
问题出现在主持人身上。我没有在用于生成cmd命令的java代码中指定主机。我需要在cmd命令中使用-h 192.168.0.44
,因此java代码段应如下所示:
File dbBackUpFile = new File("db.sql");
File mysqlDir = new File("\\\\192.168.0.44\\xampp\\mysql");
File mysqlBinDir = new File(mysqlDir, "bin");
File mysqlumpFile = new File(mysqlBinDir, "mysqldump.exe");
String dbUser = "myUserName";
String dbPass = "myPassword";
String dbName = "myDbName";
String dbIp = "192.168.0.44";
String executeCmd = "";
executeCmd = mysqlumpFile + " " + dbName + " -u " + dbUser + " -h " + dbIp
+ " --password=" + dbPass + " " + " -r \""
+ dbBackUpFile.getAbsolutePath() + "\"";