我有一个.sql文件,其中包含phpMyAdmin的导出。我想使用命令行将其导入到其他服务器。
我安装了Windows Server 2008 R2。我将.sql文件放在C驱动器上,并尝试了以下命令
database_name < file.sql
它不起作用。我遇到语法错误。
我如何才能毫无问题地导入此文件?我需要先创建数据库吗?
我有一个.sql文件,其中包含phpMyAdmin的导出。我想使用命令行将其导入到其他服务器。
我安装了Windows Server 2008 R2。我将.sql文件放在C驱动器上,并尝试了以下命令
database_name < file.sql
它不起作用。我遇到语法错误。
我如何才能毫无问题地导入此文件?我需要先创建数据库吗?
当前回答
导入数据库:
mysql-u用户名-p数据库名</file path/file_name.sql
从数据库导出:
mysqldump-u用户名-p数据库名>/file路径/file_name.sql
在这些命令之后,将出现一个提示,询问您的MySQL密码。
其他回答
要导入数据库,请使用以下命令。
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
我正在使用Windows 10和PowerShell 5,我发现几乎所有“类Unix”解决方案都不适合我。
> mysql -u[username] [database-name] < my-database.sql
At line:1 char:31
+ mysql -u[username] [database-name] < my-database.sql
+ ~
The '<' operator is reserved for future use.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported
我最终使用以下命令:
> type my-database.sql | mysql -u[username] -h[localhost] -p [database-name]
它工作得很好,希望能有所帮助。
感谢@Francesco Casula的回答,BTW。
导出特定数据库:
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并发出以下提到的命令。
mysql> use your_db_name;
mysql> source /opt/file.sql;
有时定义的端口以及该数据库的服务器IP地址也很重要。。。
mysql -u user -p user -h <Server IP address> -P<port> (DBNAME) < DB.sql