如何在没有密码提示的情况下执行mysqldump? [英] How to perform a mysqldump without a password prompt?

查看:192
本文介绍了如何在没有密码提示的情况下执行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密码提示.这是通过创建文件~/.my.cnf(权限必须为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 ~/.my.cnf (permissions need to be 600).

将此添加到.my.cnf文件

Add this to the .my.cnf 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆