如何在MySQL中使用命令行导入SQL文件? [英] How do I import an SQL file using the command line in MySQL?

查看:91
本文介绍了如何在MySQL中使用命令行导入SQL文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.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文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆