如何从命令行导出和导入带有选项的.sql文件? [重复]

本文翻译自:How to export and import a .sql file from command line with options? [duplicate]

This question already has an answer here: 这个问题在这里已有答案:

Not Duplicate! 不重复! looking for some feature have phpmyadmin during export in command line 在命令行导出期间寻找某些功能有phpmyadmin

I want to export and import a .sql file to and from a MySQL database from command line . 我想从命令行导出和导入MySQL数据库的.sql文件。

Is there any command to export .sql file in MySQL? 是否有任何命令在MySQL中导出.sql文件? 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 ? 我们可以用mysqldump设置这些选项吗?

some example of Options 选项的一些例子

在此输入图像描述


#1楼

参考:https://stackoom.com/question/LRzv/如何从命令行导出和导入带有选项的-sql文件-重复


#2楼

将整个数据库转储到文件:

mysqldump -u USERNAME -p password DATABASENAME > FILENAME.sql

#3楼

Type the following command to import sql data file: 键入以下命令以导入sql数据文件:

$ 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: 在此示例中,使用vivek作为用户名将'data.sql'文件导入'blog'数据库:

$ 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: 如果您有专用数据库服务器,请将localhost主机名替换为实际服务器名称或IP地址,如下所示:

$ 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. 请注意每种情况下的<>符号。


#4楼

尝试

mysqldump databaseExample > file.sql

#5楼

If you're already running the SQL shell, you can use the source command to import data: 如果您已经在运行SQL shell,则可以使用source命令导入数据:

use databasename;
source data.sql;

#6楼

Well you can use below command to export, 那你可以使用下面的命令导出,

mysqldump --database --user=root --password your_db_name > export_into_db.sql mysqldump --database --user = root --password your_db_name> export_into_db.sql

and the generated file will be available in the same directory where you had ran this command. 生成的文件将在您运行此命令的同一目录中可用。

Now login to mysql using command, 现在使用命令登录mysql,

mysql -u[username] -p mysql -u [用户名] -p

then use "source" command with the file path. 然后使用“source”命令和文件路径。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值