如何使用mysqlimport读取mysqldump --databases的结果 [英] How to use mysqlimport to read in result of mysqldump --databases
问题描述
我已成功使用转储了整个MySQL数据库
I have successfully dumped an entire MySQL database using
mysqldump --databases
生成一个不错的.txt文件.但是,我看不到如何一次性将整个文件读回到MySQL. mysqlimport似乎一次只需要一个表.
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.
推荐答案
使用mysqldump
生成某些文件(例如db-dump.sql
)时,可以将其导入到其他数据库中使用mysql
命令:
When you've generated some file (say db-dump.sql
) with mysqldump
, you can import it to your other database with the mysql
command :
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
附带说明一下,如果要将一个数据库复制到另一个数据库,则无需使用文件,只需将mysqldump
的输出直接传递给mysql
即可:
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 --user=XXX --password=XXX --host=SOURCE_HOST SOURCE_DB | mysql --user=XXX --password=XXX --host=DESTINATION_HOST DESTINATION_DB
(它应该更快,因为您没有使用磁盘上的临时文件)
这篇关于如何使用mysqlimport读取mysqldump --databases的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!