如何在没有密码提示的情况下执行mysqldump?

编程入门 行业动态 更新时间:2024-10-20 11:46:36
本文介绍了如何在没有密码提示的情况下执行mysqldump?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道在不提示输入密码的情况下执行数据库mysqldump的命令.

I would like to know the command to perform a mysqldump of a database without the prompt for the password.

原因: 我想运行一个cron作业,该作业每天执行一次mysqldump的数据库转储.因此,当出现提示时,我将无法插入密码.

REASON: I would like to run a cron job, which takes a mysqldump of the database once everyday. Therefore, I won't be able to insert the password when prompted.

我该如何解决?

推荐答案

由于使用的是Ubuntu,因此您所要做的只是在主目录中添加一个文件,这将禁用mysqldump密码提示.这是通过创建文件~/.myf(权限必须为600)完成的.

Since you are using Ubuntu, all you need to do is just to add a file in your home directory and it will disable the mysqldump password prompting. This is done by creating the file ~/.myf (permissions need to be 600).

将此添加到.myf文件

Add this to the .myf file

[mysqldump] user=mysqluser password=secret

这使您可以以需要密码的MySQL用户身份进行连接,而无需实际输入密码.您甚至不需要-p或--password.

This lets you connect as a MySQL user who requires a password without having to actually enter the password. You don't even need the -p or --password.

非常适合编写mysql&脚本mysqldump命令.

Very handy for scripting mysql & mysqldump commands.

实现此目标的步骤可以在此链接.

The steps to achieve this can be found in this link.

或者,您可以使用以下命令:

Alternatively, you could use the following command:

mysqldump -u [user name] -p[password] [database name] > [dump file]

但是请注意,它本质上是不安全的,因为转储运行时,系统上的任何其他用户都可以使用简单的ps ax命令来查看整个命令(包括密码).

but be aware that it is inherently insecure, as the entire command (including password) can be viewed by any other user on the system while the dump is running, with a simple ps ax command.

更多推荐

如何在没有密码提示的情况下执行mysqldump?

本文发布于:2023-11-08 20:31:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570380.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:情况下   提示   密码   如何在   mysqldump

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!