简体   繁体   English

如何使用mysqldump备份mysql?

[英]How to backup mysql using mysqldump?

I am new to using mysql and i am trying to backup a mysql database using mysqldump .我是使用 mysql 的新手,我正在尝试使用mysqldump备份 mysql 数据库。

So this is what i have done so far:-所以这就是我到目前为止所做的:-

  1. I ssh'ed into my VM and run mysql to get into the mysql CLI我通过 ssh 进入我的 VM 并运行mysql以进入mysql CLI

  2. Then i ran the command mysql> SHOW DATABASES;然后我运行命令mysql> SHOW DATABASES; which gives me the following output :-这给了我以下输出:-

    information|资讯| | | rap_songs|说唱歌曲| | | celebrities|名人|

  3. Now i am trying to backup my rap songs database and i run the following command :-现在我正在尝试备份我的rap songs数据库并运行以下命令:-

mysql> mysqldump -u root -p rap_songs > rap_songs_backup.sql

But nothing happens after this step.但是在这一步之后什么也没有发生。 What am i doing wrong?我究竟做错了什么? Any help will be appreciated.任何帮助将不胜感激。 thank you.谢谢你。

Run mysqldump in SSH terminal not in mysql terminalSSH terminal而不是mysql terminal运行mysqldump

For all database::对于所有数据库::

mysqldump --all-databases --single-transaction -u root -p > /all_databases.sql

For one database ( rap_song in this case)::对于一个数据库(在本例中为rap_song )::

mysqldump -u root -p rap_songs > /your_backup.sql

Now you need to go to / to see your files, mysqldump usually show nothing once its done terminal again avail for new cmd.现在您需要转到/查看您的文件,一旦完成终端再次可用于新的 cmd, mysqldump通常不会显示任何内容。 So if terminal is again avail it means its done!因此,如果终端再次可用,则意味着它完成了!

Non-root user |非root用户| Permission denied error!权限被拒绝错误!

Don't use /your_backup.sql不要使用/your_backup.sql

use ~/your_backup.sql instead改用~/your_backup.sql

~/ is your user data directory ~/是您的用户数据目录

Mysqldump without password没有密码的mysqldump

You can create a .my.cnf in ~/您可以在~/创建一个.my.cnf

[mysqldump]
user=mysqluser
password=userpass

Then chmod 600 ~/.my.cnf然后chmod 600 ~/.my.cnf

now in your script or crontab don't mention -p or --password and when your cron or script execute it will automatically pick password from here现在在您的脚本或 crontab 中不要提及-p--password ,当您的 cron 或脚本执行时,它会自动从这里选择密码

Okay so I had to run this query in order to circumvent the errors :-好的,所以我必须运行此查询以规避错误:-

mysqldump --complete-insert --routines --triggers --single-transaction
    rap_songs> rap_songs_backup.sql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM