【问题标题】:how to set mysql root password in a chef cookbook?如何在厨师食谱中设置 mysql root 密码?
【发布时间】:2018-07-05 12:52:08
【问题描述】:

我正在使用这个mysql chef cookbook。食谱应该允许您设置 mysql root 密码。它通过以下方式做到这一点

    def init_records_script
      # Note: shell-escaping passwords in a SQL file may cause corruption - eg
      # mysql will read \& as &, but \% as \%. Just escape bare-minimum \ and '
      sql_escaped_password = root_password.gsub('\\') { '\\\\' }.gsub("'") { '\\\'' }
      Chef::Log.info("passxyz" + sql_escaped_password)
      <<-EOS
        set -e
        rm -rf /tmp/#{mysql_name}
        mkdir /tmp/#{mysql_name}

        cat > /tmp/#{mysql_name}/my.sql <<-'EOSQL'
UPDATE mysql.user SET #{password_column_name}=PASSWORD('#{root_password}')#{password_expired} WHERE user = 'root';
DELETE FROM mysql.user WHERE USER LIKE '';
FLUSH PRIVILEGES;
DELETE FROM mysql.db WHERE db LIKE 'test%';
DROP DATABASE IF EXISTS test ;
EOSQL

       #{db_init}
       #{record_init}

       while [ ! -f #{pid_file} ] ; do sleep 1 ; done
       kill `cat #{pid_file}`
       while [ -f #{pid_file} ] ; do sleep 1 ; done

       EOS
    end

def record_init
      cmd = v56plus ? mysqld_bin : mysqld_safe_bin
      cmd << " --defaults-file=#{etc_dir}/my.cnf"
      cmd << " --init-file=/tmp/#{mysql_name}/my.sql"
      cmd << ' --explicit_defaults_for_timestamp' if v56plus
      cmd << ' &'
      return "scl enable #{scl_name} \"#{cmd}\"" if scl_package?
      cmd
    end

上面似乎正在尝试执行命令: /usr/bin/mysqld_safe --defaults-file=/etc/mysql/my.cnf --init-file=/tmp/mysql/my.sql &amp;我试图寻找文件来检查它,但找不到它。所以这似乎不起作用。最终,使用这本食谱,mysql root 密码根本没有设置。上面有什么明显的错误吗?我该如何调试它?

【问题讨论】:

    标签: mysql ruby vagrant chef-infra


    【解决方案1】:

    看来the chef resource bashinit_records_script 作为输入参数需要user "root" 属性。看到这个公关: https://github.com/chef-cookbooks/mysql/pull/541

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 2013-06-22
      • 1970-01-01
      • 1970-01-01
      • 2017-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多