我有一个.sql文件,其中包含phpMyAdmin的导出。我想使用命令行将其导入到其他服务器。

我安装了Windows Server 2008 R2。我将.sql文件放在C驱动器上,并尝试了以下命令

database_name < file.sql

它不起作用。我遇到语法错误。

我如何才能毫无问题地导入此文件?我需要先创建数据库吗?


当前回答

要导入数据库,请使用以下命令。

mysql> create new_database;
mysql> use new_database;
mysql> source (Here you need to import the path of the SQL file);

E.g.:
mysql> source E:/test/dump.sql;

即使在Windows上,也需要使用正斜杠(/),例如e:/test/dump.sql而不是e:\test\dump.sql

或由于转义而使用双反斜杠(\\),即e:\\test\\dump.sql

其他回答

mysql --user=[user] --password=[password] [database] < news_ml_all.sql

试试看:

cd C:\xampp\mysql\bin
mysql -u root -p database_name --force < C:\file.sql

导出特定数据库:

mysqldump --user=root --host=localhost --port=3306 --password=test -B CCR KIT > ccr_kit_local.sql

这将导出CCR和KIT数据库。。。

将所有导出的数据库导入到特定的MySQL实例(您必须在转储文件所在的位置):

mysql --user=root --host=localhost --port=3306 --password=test < ccr_kit_local.sql

关于导入巨大文件所需的时间:最重要的是,它需要更多的时间,因为MySQL的默认设置是autocommit=true。您必须在导入文件之前将其设置为关闭,然后检查导入是如何像宝石一样工作的。

您只需执行以下操作:

mysql> use db_name;

mysql> SET autocommit=0 ; source the_sql_file.sql ; COMMIT ;

要导入数据库,请使用以下命令。

mysql> create new_database;
mysql> use new_database;
mysql> source (Here you need to import the path of the SQL file);

E.g.:
mysql> source E:/test/dump.sql;

即使在Windows上,也需要使用正斜杠(/),例如e:/test/dump.sql而不是e:\test\dump.sql

或由于转义而使用双反斜杠(\\),即e:\\test\\dump.sql