如何使用选项从命令行导出和导入 .sql 文件? [英] How to export and import a .sql file from command line with options?

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

问题描述

不重复!在命令行导出期间寻找一些具有phpmyadmin的功能

我想从 命令行 向 MySQL 数据库导出和导入 .sql 文件.

是否有任何命令可以在 MySQL 中导出 .sql 文件?那我怎么导入呢?

在进行导出/导入时,可能存在约束,例如启用/禁用外键检查仅导出表结构.>

我们可以用mysqldump设置那些选项吗?

选项示例

解决方案

输入以下命令导入sql数据文件:

$ mysql -u username -p -h localhost DATA-BASE-NAME <数据.sql

在这个例子中,使用 vivek 作为用户名将 'data.sql' 文件导入到 'blog' 数据库中:

$ mysql -u vivek -p -h localhost blog <数据.sql

如果您有专用的数据库服务器,请将 localhost 主机名替换为实际服务器名称或 IP 地址,如下所示:

$ mysql -u 用户名 -p -h 202.54.1.10 数据库名 <数据.sql

要导出数据库,请使用以下命令:

mysqldump -u 用户名 -p 数据库名 >文件名.sql

注意每种情况下的 <> 符号.

Not Duplicate! looking for some feature have phpmyadmin during export in command line

I want to export and import a .sql file to and from a MySQL database from command line.

Is there any command to export .sql file in MySQL? Then how do I import it?

When doing the export/import, there may be constraints like enable/disable foreign key check or export only table structure.

Can we set those options with mysqldump?

some example of Options

解决方案

Type the following command to import sql data file:

$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql

In this example, import 'data.sql' file into 'blog' database using vivek as username:

$ mysql -u vivek -p -h localhost blog < data.sql

If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:

$ mysql -u username -p -h 202.54.1.10 databasename < data.sql

To export a database, use the following:

mysqldump -u username -p databasename > filename.sql

Note the < and > symbols in each case.

这篇关于如何使用选项从命令行导出和导入 .sql 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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