问题描述
我有一个.sql
文件,并且从phpMyAdmin
导出了文件.我想使用命令行将其导入到其他服务器中.
I have a .sql
file with an export from phpMyAdmin
. I want to import it into a different server using the command line.
我有 Windows Server 2008 R2安装.我将.sql
文件放置在 C驱动器 上,并尝试了该命令
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.
- 如何顺利导入该文件?
- 我需要首先创建一个数据库吗?
推荐答案
尝试:
mysql -u username -p database_name < file.sql
检查 MySQL选项.
注1::最好使用SQL文件file.sql
的完整路径.
Note-1: It is better to use the full path of the SQL file file.sql
.
注2::使用-R
和--triggers
保留原始数据库的例程和触发器.默认情况下,不会复制它们.
Note-2: Use -R
and --triggers
to keep the routines and triggers of original database. They are not copied by default.
注3 ,如果该数据库不存在并且导出的SQL不包含CREATE DATABASE
(用--no-create-db
或--no-create-db
导出),则可能必须从mysql创建(空)数据库. -n
选项),然后再导入.
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文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!