从 MySql 导出转储文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7423654/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Export dump file from MySql
提问by frazman
I want to create a dump file of a table in the database. So database --> king, tablename --> castle So what I want to do is create a dump file.. and then the next part is to import it in my local host. database name --> king_local. Any ideas on how to go about this!! Thanks
我想在数据库中创建一个表的转储文件。所以数据库-->国王,表名-->城堡所以我想做的是创建一个转储文件..然后下一部分是将它导入到我的本地主机中。数据库名称--> king_local. 关于如何解决这个问题的任何想法!!谢谢
回答by Mohit Jain
To export:
导出:
mysqldump -u mysql_user -p DATABASE_NAME > backup.sql
To import:
导入:
mysql -u mysql_user -p DATABASE < backup.sql
回答by Kenny
Since you now seem to want to export the data from within the MySQL monitor, you want to look at the documentation from MySQL on SELECT ... INTO OUTFILE:
由于您现在似乎想从 MySQL 监视器中导出数据,因此您想查看 MySQL 中关于 SELECT ... INTO OUTFILE 的文档:
http://dev.mysql.com/doc/refman/5.0/en/select.html
http://dev.mysql.com/doc/refman/5.0/en/select.html
The INTO OUTFILE stuff is what you'd use to dump data in to said "outfile", and you'd want to specify the full path to a location that MySQL can write to, for example /tmp/dump.sql.
INTO OUTFILE 是你用来将数据转储到所说的“输出文件”的东西,你想指定 MySQL 可以写入的位置的完整路径,例如 /tmp/dump.sql。
You'll then want to pay attention to the docs so you can specify how to end lines, delimit fields etc:
然后,您需要注意文档,以便您可以指定如何结束行、分隔字段等:
FIELDS TERMINATED BY, ENCLOSED BY, ESCAPED BY, LINES TERMINATED
字段被终止,被包围,被转义,被终止的行
And then to load it back in, LOAD DATA INFILE seems to be what you want. Go to that URL I posted, it has everything you seem to want.
然后将其重新加载, LOAD DATA INFILE 似乎是您想要的。转到我发布的那个 URL,它有你想要的一切。
回答by Senthil
For example, to dump table definitions and data separately use these commands:
例如,要分别转储表定义和数据,请使用以下命令:
mysqldump -u mysql_user -p --no-data test > dump-defs.sql
mysqldump -u mysql_user -p --no-create-info test > dump-data.sql
回答by manian
For Exporting a database from WAMP in windows, please follow the below steps
1. Open Command Prompt
2. Change Directory to the bin folder of mysql(eg., CD C:\wamp64\bin\mysql\mysql5.7.14\bin)
3. Run the below command where 'password' is your mysql root password, 'dbname' is your database name & path within the doubles quotes is your directory where you want to save your file.
在 windows 中从 WAMP 导出数据库,请按照以下步骤操作
1. 打开命令提示符
2. 将目录更改为 mysql 的 bin 文件夹(例如,CD C:\wamp64\bin\mysql\mysql5.7.14\bin)
3 . 运行以下命令,其中 'password' 是您的 mysql root 密码,'dbname' 是您的数据库名称,双引号中的路径是您要保存文件的目录。
Command:
命令:
mysqldump -u root -p password dbname > "D:\db\db_backup.sql"