vagrant ssh provisioning - mysql密码

Dra*_*gos 1 mysql provisioning vagrant

我正在使用SSH配置构建一个Vagrant盒子(CentOS 6.4).

All's running fine, LAMP components installed and started but I've reached the step where I should secure MySql (set mysql password, etc).

There's mysql_secure_installation that could be run, but it doesn't work in a non-interactive mode.

I could run

 /usr/bin/mysqladmin -u root password 'newpassword' 
Run Code Online (Sandbox Code Playgroud)

but if I provision the same box multiple times, Mysql will accept a new password the first time, but then will complain.

Is there an elegant way of securing MySql, automatically, at provisioning time? (I'm not using Chef/Puppet, just simple SSH provisioning)

Emy*_*myl 5

可能的方法是:

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

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