Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vagrant ssh配置-mysql密码_Mysql_Vagrant_Provisioning - Fatal编程技术网

vagrant ssh配置-mysql密码

vagrant ssh配置-mysql密码,mysql,vagrant,provisioning,Mysql,Vagrant,Provisioning,我正在使用SSH配置构建一个流浪者箱(CentOS 6.4) 一切运行正常,安装并启动了LAMP组件,但我已经达到了保护MySql(设置MySql密码等)的步骤 mysql\u secure\u安装可以运行,但在非交互模式下无法运行 我可以跑 /usr/bin/mysqladmin -u root password 'newpassword' 但是如果我多次设置同一个框,Mysql会在第一次接受新密码,但随后会抱怨 有没有一种优雅的方法可以在资源调配时自动保护MySql?(我没有使用Che

我正在使用SSH配置构建一个流浪者箱(CentOS 6.4)

一切运行正常,安装并启动了LAMP组件,但我已经达到了保护MySql(设置MySql密码等)的步骤

mysql\u secure\u安装可以运行,但在非交互模式下无法运行

我可以跑

 /usr/bin/mysqladmin -u root password 'newpassword' 
但是如果我多次设置同一个框,Mysql会在第一次接受新密码,但随后会抱怨


有没有一种优雅的方法可以在资源调配时自动保护MySql?(我没有使用Chef/Puppet,只是简单的SSH配置)

一种可能的方法是:

/usr/bin/mysql -uroot -pnewpassword -e 'SELECT CURDATE();' || /usr/bin/mysqladmin -u root password 'newpassword'

说明:脚本首先尝试使用新密码连接到mysql,只有在失败时(即密码尚未设置)才会执行命令进行设置。

一种可能的方法是:

/usr/bin/mysql -uroot -pnewpassword -e 'SELECT CURDATE();' || /usr/bin/mysqladmin -u root password 'newpassword'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'

说明:脚本首先尝试使用新密码连接到mysql,只有在失败时(即密码尚未设置)才会执行命令进行设置。

sudo-debconf-set-selections
sudo-debconf-set-selections在
Vagrantfile
中添加以下行:

sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
   <other code>
   ...
    config.vm.provision "shell", 
       inline: "mysqladmin -uroot -pcurrentpass password newpassword"

end
Vagrant.configure(Vagrant文件API版本)do | config|
...
config.vm.provision“shell”,
内联:“mysqladmin-uroot-pcurrentpasswordnewpassword”
结束

在您的
vagrant文件中添加行,如下所示:

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
   <other code>
   ...
    config.vm.provision "shell", 
       inline: "mysqladmin -uroot -pcurrentpass password newpassword"

end
Vagrant.configure(Vagrant文件API版本)do | config|
...
config.vm.provision“shell”,
内联:“mysqladmin-uroot-pcurrentpasswordnewpassword”
结束