MySQL 如何使用mysqlimport读取mysqldump --databases的结果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2298176/
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
How to use mysqlimport to read in result of mysqldump --databases
提问by Charles Anderson
I have successfully dumped an entire MySQL database using
我已经成功地使用了转储了整个 MySQL 数据库
mysqldump --databases
generating a nice .txt file. However, I can't see how to read the whole file back into MySQL in one go; mysqlimport seems to want just one table at a time.
生成一个不错的 .txt 文件。但是,我看不到如何一口气将整个文件读回 MySQL;mysqlimport 似乎一次只需要一张表。
回答by Pascal MARTIN
When you've generated some file (say db-dump.sql
)with mysqldump
, you can import it to your other database with the mysql
command :
当您使用 生成了一些文件(例如db-dump.sql
)后mysqldump
,您可以使用以下mysql
命令将其导入其他数据库:
mysql --user=XXX --password=XXX --host=YOUR_HOST DATABASE_NAME < db-dump.sql
And, if you don't want the password to appear in a command, you can use :
而且,如果您不希望密码出现在命令中,您可以使用:
mysql --user=XXX -p --host=YOUR_HOST DATABASE_NAME < db-dump.sql
As a sidenote, if you want to copy one DB to another one, you don't need to use a file, and can just directly pipe the output of mysqldump
to mysql
:
作为旁注,如果要将一个数据库复制到另一个数据库,则不需要使用文件,只需直接将mysqldump
to的输出通过管道传输mysql
:
mysqldump --user=XXX --password=XXX --host=SOURCE_HOST SOURCE_DB | mysql --user=XXX --password=XXX --host=DESTINATION_HOST DESTINATION_DB
(It should even be faster, as you're not using a temporary file that resides on disk)
(它应该更快,因为您没有使用驻留在磁盘上的临时文件)
回答by Evgeny
I do this frequently:
我经常这样做:
mysqldump -u username -p databasename > dump.sql
To load:
装载:
mysql -u username -p targetdatabasename < dump.sql
Switch -p
instructs the database to prompt you to enter the password for the user username
once the command launches.
Switch-p
指示数据库username
在命令启动后提示您输入用户的密码。
Your question is probably duplicate though.
不过,您的问题可能是重复的。
回答by Joe
You can just use 'source' from within the mysql client:
您可以在 mysql 客户端中使用“源”:
source dumpfile.sql
Or supply directly from command line:
或者直接从命令行提供:
mysql -u user -p password database < source dumpfile.sql
This is because the result of mysqldump is just a SQL file that can be run via mysql as usual.
这是因为 mysqldump 的结果只是一个 SQL 文件,可以照常通过 mysql 运行。