如何使用MySQL中的命令行导入SQL文件?(How to import an SQL file using the command line in MySQL?)

我有一个从phpMyAdmin导出的.sql文件。 我想使用命令行将其导入到不同的服务器。

我有一个Windows Server 2008 R2安装。 我把.sql文件放在C盘上,我试过这个命令

database_name < file.sql

它不工作我得到语法错误。

如何导入此文件没有问题? 我需要先创建数据库吗?

I have a .sql file with an export from phpMyAdmin. I want to import it into a different server using the command line.

I have a Windows Server 2008 R2 installation. I placed the .sql file on the C drive, and I tried this command

database_name < file.sql

It is not working I get syntax errors.

How can I import this file without a problem? Do I need to create a database first?

最满意答案

尝试:

mysql -u username -p database_name < file.sql

检查MySQL选项 。

注意:最好使用SQL文件file.sql的完整路径。

Try:

mysql -u username -p database_name < file.sql

Check MySQL Options.

Note-1: It is better to use the full path of the SQL file file.sql.

Note-2: Use -R and --triggers to keep the routines and triggers of original database. They are not copied by default.

Note-3 You may have to create the (empty) database from mysql if it doesn't exist already and the exported SQL don't contain CREATE DATABASE (exported with --no-create-db or -n option), before you can import it.

如何使用MySQL中的命令行导入SQL文件?(How to import an SQL file using the command line in MySQL?)

我有一个从phpMyAdmin导出的.sql文件。 我想使用命令行将其导入到不同的服务器。

我有一个Windows Server 2008 R2安装。 我把.sql文件放在C盘上,我试过这个命令

database_name < file.sql

它不工作我得到语法错误。

如何导入此文件没有问题? 我需要先创建数据库吗?

I have a .sql file with an export from phpMyAdmin. I want to import it into a different server using the command line.

I have a Windows Server 2008 R2 installation. I placed the .sql file on the C drive, and I tried this command

database_name < file.sql

It is not working I get syntax errors.

How can I import this file without a problem? Do I need to create a database first?

最满意答案

尝试:

mysql -u username -p database_name < file.sql

检查MySQL选项 。

注意:最好使用SQL文件file.sql的完整路径。

Try:

mysql -u username -p database_name < file.sql

Check MySQL Options.

Note-1: It is better to use the full path of the SQL file file.sql.

Note-2: Use -R and --triggers to keep the routines and triggers of original database. They are not copied by default.

Note-3 You may have to create the (empty) database from mysql if it doesn't exist already and the exported SQL don't contain CREATE DATABASE (exported with --no-create-db or -n option), before you can import it.