如何在没有密码提示的情况下执行 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)