[英]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:-所以这就是我到目前为止所做的:-
I ssh'ed into my VM and run mysql
to get into the mysql CLI
我通过 ssh 进入我的 VM 并运行
mysql
以进入mysql CLI
Then i ran the command mysql> SHOW DATABASES;
然后我运行命令
mysql> SHOW DATABASES;
which gives me the following output :-这给了我以下输出:-
information|资讯| |
| rap_songs|
说唱歌曲| |
| celebrities|
名人|
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 terminal
在
SSH 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.