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

How to perform a mysqldump without a password prompt?(如何在没有密码提示的情况下执行 mysqldump?)
本文介绍了如何在没有密码提示的情况下执行 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.

我该如何解决这个问题?

How could I solve this ?

推荐答案

由于您使用的是 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 文件

[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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)