How to set root password in mysql using chef?


I am trying to set mysql root password from using chef recipe. Below is the code. But i am getting error.

mysql_service 'default' do
  port '3306'
  version '5.7.24'
  initial_root_password 'test@123'
  action [:create, :start]

NoMethodError: undefined method `mysql_service' for cookbook

I don't use mysql cookbook chef supermarket. Installation steps are included below. How can i do this?

directory '/opt/mysql' do
  owner 'root'
  group 'root'
  mode '0755'
  action :create

remote_file "/opt/mysql/mysql57-community-release-el7-9.noarch.rpm" do
   source "                                                                                        h.rpm"

package 'mysql57-community-release-el7-9.noarch.rpm' do
   source '/opt/mysql/mysql57-community-release-el7-9.noarch.rpm'
   action :install

package 'mysql-server' do
   action :install

service "mysqld" do
   action [ :enable, :start ]


Hi Janith,

What is the current chef-client version? Mysql_service resource is not so old so I am defiantly sure that you want to upgrade the chef-client package first.



Thank you for your response. Below I include versions.

Chef Development Kit Version: 3.6.57
chef-client version: 14.8.12
delivery version: master (5fb4908da53579c9dcf4894d4acf94d2d9ee6475)
berks version: 7.0.7
kitchen version: 1.24.0
inspec version: 3.2.6


This is same problem for me .I need to install mysql2_chef_gem but iam getting error
If i try to install mysql2_chef_gem i get error Package: No candidate version available for mysql-community-client, mysql-community-devel.
Its quite difficult situation for me and iam still not able to find any solution.
Did you find any solution pls let me know.Thanks.