[英]Install mysql shellscript and set root password
I need staff to make a shell script that installs mysql server with yum however need to install it sets the root password mysql automatically! 我需要工作人员制作一个外壳脚本,用yum安装mysql服务器,但是需要安装它会自动设置root密码mysql! Most do not know how to do this can anyone help me?
大多数人不知道该怎么做,有人可以帮助我吗?
One way would be to specify the password afterwards (when you know the default) 一种方法是在以后指定密码(当您知道默认密码时)
mysqladmin -u root password <NEW_PASS>
You can try to make that part of your script. 您可以尝试将其作为脚本的一部分。
The other way would be to use here-strings . 另一种方法是使用here-strings 。
It will basically look something like this: 基本上看起来像这样:
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password <NEW_PASS>'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password <NEW_PASS>'
sudo apt-get -y install mysql-server
Third way would be to use a real provisioning framework like Chef or Puppet or other, where you use files to describe a certain type of node, similar to this: 第三种方法是使用诸如Chef或Puppet或其他类似的真实配置框架,在其中使用文件来描述某种类型的节点,类似于:
class mysql-server {
$password = "insert_password_here"
package { "MySQL-client": ensure => installed }
package { "MySQL-server": ensure => installed }
package { "MySQL-shared": ensure => installed }
exec { "Set MySQL server root password":
subscribe => [ Package["MySQL-server"], Package["MySQL-client"], Package["MySQL-shared"] ],
refreshonly => true,
unless => "mysqladmin -uroot -p$password status",
path => "/bin:/usr/bin",
command => "mysqladmin -uroot password $password",
}
}
Check out the full article here . 在此处查看全文。
Further resources: 更多资源:
[1]Configuration management mysql with chef [1] 带厨师的配置管理mysql
[2]Configuration management mysql with Puppet [2] 使用Puppet进行配置管理mysql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.