如何从MySQL中的.bat文件导入数据?

时间:2021-06-16 07:06:42

I created a .bat file (import_file.bat):

我创建了一个.bat文件(import_file.bat):

set database_name=nome_db
mysql –u root --password=pass --database %database_name% < c:/import_geco/sql_svuta.sql
mysql –u root --password=pass --database %database_name% < c:/import_geco/carica_dati.sql

From the command line, in the MySQL bin directory I entered:

从命令行,在我输入的MySQL bin目录中:

mysql/bin>c:/import_db/import_file.bat

... but it doesn't work, instead it returns MySQL help info.

...但它不起作用,而是返回MySQL帮助信息。

If I create a .bat file to export table (export.bat):

如果我创建一个.bat文件导出表(export.bat):

mysqldump --no-create-info -u root nome_db nome_tabella  > c:/backup_db/export.sql

... and enter at the command line:

...并在命令行输入:

mysql/bin>c:/import_db/export.bat

it works.

1 个解决方案

#1


0  

You get the help file because you have a malformed command. You are attempting to pipe something to the command line. YOu probably need to use the -e (--execute) command, and you can either pipe the file or use LOAD DATA FILE

您获得了帮助文件,因为您的命令格式错误。您正在尝试将某些内容传递给命令行。你可能需要使用-e(--execute)命令,你可以管道文件或使用LOAD DATA FILE

see: http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html

#1


0  

You get the help file because you have a malformed command. You are attempting to pipe something to the command line. YOu probably need to use the -e (--execute) command, and you can either pipe the file or use LOAD DATA FILE

您获得了帮助文件,因为您的命令格式错误。您正在尝试将某些内容传递给命令行。你可能需要使用-e(--execute)命令,你可以管道文件或使用LOAD DATA FILE

see: http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html