我想知道在不提示输入密码的情况下执行数据库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?
发布评论