MySQL Installation

Hi Experts,
I have installed the Mysql via chef.
As all the mysql cookbook are deprecated and
mysql_service 'default' do
version '5.7'
bind_address '0.0.0.0'
port '3306'
data_dir '/data'
initial_root_password 'Ch4ng3me'
action [:create, :start]
end
The above does not work for me , is there any other way to change the initial password .Any help will be very helpful.

Look at the current MySQL cookbook maintained by the sous-chefs team

Yes you can set the initial root password

1 Like

Thanks i have a strange issue iam changing the password , The password is getting changed successfully but i get this error.

from the kitchen converge

Running handlers:
First chef run should have reached a converged state.
Resources updated in a second chef-client run:
- bash[create databass]
[2019-02-25T13:45:58+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process terminated by signal 9 (KILL)
[2019-02-25T13:45:58+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process terminated by signal 9 (KILL)

am using simple command to change root password after MySql installation ,But getting the Above error (signal 9 kill)

script "change password" do

interpreter "bash"

user "root"

cwd "/tmp"

code <<-EOH

#MYSQL

root_temp_pass=$(grep 'A temporary password' /mysql/log/mysqld.log |tail -1 |awk '{split($0,a,": "); print a[2]}')

#Login as root change password

mysql -uroot -p"$root_temp_pass" -Be "ALTER USER 'root'@'localhost' IDENTIFIED BY 'Czt732ck#';" --connect-expired-password

EOH

end

Thank you , Iam able to change the password while creating database iam getting the error

  • bash[create databasss]
    [2019-02-25T18:00:00+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process terminated by signal 9 (KILL)
    [2019-02-25T18:00:00+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process terminated by signal 9 (KILL)

Any pointers will be very helpful on this .

So first I'll preface this. I use the mysql cookbook for installing mysql percona - despite there being a percona cookbook. Your milage may vary.

defaults.rb

default['mysql_wrapper']['pins'] = {
  server:     '5.7.17-13.1.el7',
  xtrabackup: '2.4.11-1.el7',
  toolkit:    '3.0.10-1.el7',
}

default['mysql_wrapper']['packages'] = {
  "Percona-Server-client-#{node['mysql_wrapper']['pins']['server'].split('.').first(2).join('')}" =>            node['mysql_wrapper']['pins']['server'],
  "Percona-Server-devel-#{node['mysql_wrapper']['pins']['server'].split('.').first(2).join('')}" =>             node['mysql_wrapper']['pins']['server'],
  "Percona-Server-server-#{node['mysql_wrapper']['pins']['server'].split('.').first(2).join('')}" =>            node['mysql_wrapper']['pins']['server'],
  "Percona-Server-shared-#{node['mysql_wrapper']['pins']['server'].split('.').first(2).join('')}" =>            node['mysql_wrapper']['pins']['server'],
  "Percona-Server-shared-compat-#{node['mysql_wrapper']['pins']['server'].split('.').first(2).join('')}" =>     node['mysql_wrapper']['pins']['server'],
  "Percona-Server-#{node['mysql_wrapper']['pins']['server'].split('.').first(2).join('')}-debuginfo" =>         node['mysql_wrapper']['pins']['server'],
  "percona-xtrabackup-#{node['mysql_wrapper']['pins']['xtrabackup'].split('.').first(2).join('')}" =>           node['mysql_wrapper']['pins']['xtrabackup'],
  "percona-xtrabackup-#{node['mysql_wrapper']['pins']['xtrabackup'].split('.').first(2).join('')}-debuginfo" => node['mysql_wrapper']['pins']['xtrabackup'],
  'percona-nagios-plugins' =>                                                                                   '1.1.8-1',
  'percona-toolkit' =>                                                                                          node['mysql_wrapper']['pins']['toolkit'],
  'percona-toolkit-debuginfo' =>                                                                                node['mysql_wrapper']['pins']['toolkit'],
  'nfs-utils' =>                                                                                                nil,
  'qpress' =>                                                                                                   '11-1.el7',
  'rsync' =>                                                                                                    nil,
  expect:                                                                                                       nil,
  mailx:                                                                                                        nil,
}

service.rb

require 'securerandom'
percona_client = node['mysql_wrapper']['packages'].select { |key, _val| key.include? 'Percona-Server-client' }.keys[0]
percona_sauce = SecureRandom.base64(32)
percona_server = node['mysql_wrapper']['packages'].select { |key, _val| key.include? 'Percona-Server-server' }.keys[0]

mysql_service node['mysql_wrapper']['service']['name'] do
  version               node['mysql_wrapper']['packages'][percona_server]
  bind_address          node['mysql_wrapper']['service']['ip']
  package_name          percona_server
  port                  node['mysql_wrapper']['service']['port']
  data_dir              node['mysql_wrapper']['service']['paths']['dbdata']
  error_log             ::File.join(node['mysql_wrapper']['service']['paths']['log'], 'mysql-error.log')
  initial_root_password percona_sauce
  subscribes            :restart, "template[#{::File.join('/etc/systemd/system/', "mysql-#{name}.d", 'limits.conf')}]", :delayed
  action                [:create, :start]
end

bash 'mylogin.cnf' do
  code <<-MLC
    expect -c '
    set timeout 10
    spawn mysql_config_editor set --login-path=#{node['mysql_wrapper']['service']['name']} --host=localhost --user=root --port=#{node['mysql_wrapper']['service']['port']} --socket=#{::File.join('/var/run', "mysql-#{node['mysql_wrapper']['service']['name']}", 'mysqld.sock')} --password
    expect "password:"
    send "#{percona_sauce}\r"
    expect eof'
  MLC
  cwd       '/root'
  creates   '/root/.mylogin.cnf'
  sensitive true
  user      'root'
end

# ... a few other things

mysql_config node['mysql_wrapper']['service']['name'] do
  instance node['mysql_wrapper']['service']['name']
  source   'my.cnf.erb'
  variables mysql: node['mysql_wrapper']['config']
  notifies :restart, "mysql_service[#{name}]", :delayed
end

So what's all this code achieve? Well we call securerandom so that we can generate a secure password. Now even I don't know the password here, and this is the point of the bash block. It generates the encrypted login file using MySQL's encrypted profile format. The profile (known here by the login-path command option), is the name of the instance declared by my node['mysql_wrapper']['service']['name'] attribute. So if node['mysql_wrapper']['service']['name'] = 'myserver1', you'd log into the mysql instance with mysql --login-path=myserver1 from the root user.

I do not use the default mysql server instance, and always use a named instance. That might be where you're getting some issues, because a named instance uses a different socket file.

This is how I've been spawning MySQL instances for a while now.