简体   繁体   English

在没有提示的情况下从python-fabric重置mysql root密码

[英]Resetting mysql root password from python-fabric without prompt

I'm trying to automate a deployment of an application by Python-fabric. 我正在尝试通过Python-fabric自动化应用程序的部署。 The installation has to be done without any human intervention. 安装必须在没有任何人工干预的情况下进行。

In CentOS 6.4 server the if i install mysql through 在CentOS 6.4服务器中,如果我通过安装mysql

$yum install mysql-server

Then mysql is installed with a NULL password. 然后使用空密码安装mysql。

Now the problem is when i reset the mysql root password from fabric by issuing : 现在的问题是,当我通过发出以下命令从结构中重置mysql根密码时:

run("mysqladmin -u %s -p password %s " % ('root','khd5u8bWN'))

It prompts for a password (which is NULL) and i have to press the return key to proceed. 它提示输入密码(为NULL),我必须按回车键才能继续。

Now as i want to achieve "full" automation, i want this "pressing enter" automatically. 现在,当我要实现“完全”自动化时,我希望这种“按Enter”会自动进行。 How can i achieve this in python-fabric? 我如何在python-fabric中实现呢?

When a mysql password is empty you can login to that account by omitting the -p option. 当mysql密码为空时,您可以通过省略-p选项来登录该帐户。 So change your run command to: 因此,将您的运行命令更改为:

run("mysqladmin -u %s password %s " % ('root','khd5u8bWN'))

You could either set the environment variable password in the env dict ( "" should work if the password is no password) or invoke fab with the -I <pwd> option. 您既可以设置环境变量passwordenv dict (“”应该工作,如果密码是没有密码),或者调用fab-I <pwd>选项。

I generally use the latter option, since it's code agnostic. 我通常使用后一种选项,因为它与代码无关。

Edit in response to OP's comment: 根据OP的评论进行编辑:

Try switching from using run to sudo to run the command (while still using one of the methods above). 尝试从使用run切换到sudo来运行命令(同时仍使用上述方法之一)。

Edit 2 in response to OP's follow-up comment: 编辑2以回应OP的后续评论:

I'm pretty sure sudo is the key here, based on the info provided, but perhaps with certain arguments set. 基于提供的信息,我很确定sudo是关键,但也许设置了某些参数。 See http://docs.fabfile.org/en/latest/api/core/operations.html#fabric.operations.sudo 请参阅http://docs.fabfile.org/en/latest/api/core/operations.html#fabric.operations.sudo

Edit 3 in response to add'l OP follow-up comment: 编辑3以回应添加OP后续评论:

Re: it being the mysql root password and not an OS password, this may provide some food for thought: install mysql on ubuntu without password prompt 回复:这是mysql root密码,而不是OS的密码,这可能会引起一些思考: 在没有密码提示的情况下在ubuntu上安装mysql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM