MySQL 如何通过命令行导出数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8217578/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:46:50  来源:igfitidea点击:

How to export databases through command line?

mysqlcommand-line

提问by good_evening

I have URL of phpMyAdmin, I have username and password. How can I export all those databases? Because phpMyAdmin crashes when I try to export them, so I want to try it through command line.

我有 phpMyAdmin 的 URL,我有用户名和密码。如何导出所有这些数据库?因为phpMyAdmin在我尝试导出时崩溃了,所以我想通过命令行尝试一下。

回答by matthiasmullie

mysqldump -uUSERNAME -pPASSWORD -hHOSTNAME USER_DATABASE > FILENAME.sql

Then import using:

然后导入使用:

mysql -uUSERNAME -pPASSWORD -hHOSTNAME USER_DATABASE < FILENAME.sql

回答by djdy

mysqldump -u user -p db_name > db_file.sql

mysqldump -u user -p db_name > db_file.sql

Edit: based on the comments on another answer.

编辑:基于对另一个答案的评论。

If MySQL server allows for remote connections, then you can run this command on another machine you do have access to.

如果 MySQL 服务器允许远程连接,那么您可以在您有权访问的另一台机器上运行此命令。

mysqldump -h hostname-of-your-server -u user -p db_name > db_file.sql

mysqldump -h hostname-of-your-server -u user -p db_name > db_file.sql

回答by Hasanuzzaman Sattar

If you want to export all databases at a single command at the same time, use the following command instead.

如果要同时通过单个命令导出所有数据库,请改用以下命令。

mysqldump -u <THE USERNAME> -p --all-databases > all_databases.sql

回答by Habib Rehman

As i was logged into my server already there i just had to put this command to dump db

当我已经登录到我的服务器时,我只需要将此命令转储 db

 mysqldump --databases  database_name > file_name.sql