2

I'm provisioning a Vagrant bento/centos6.7 box using chef_solo provisioner. I'm using berkshelf-plugin for the cookbook dependencies.

My project folder looks like this:

|── Vagrantfile
|── cookbooks
    └── my_cookbook
        |── Berksfile
        |── metadata.rb
...

Inside my Vagrantfile (which is the default for bento/centos6.7 plus the following config)

config.berkshelf.enabled = true
config.berkshelf.berksfile_path = "cookbooks/my_cookbook/Berksfile"

config.vm.provision "chef_solo" do |chef|
  chef.add_recipe "my_cookbook"
end

In my metadata.rb

depends 'mysql2_chef_gem', '~> 1.1'
depends 'database', '~> 5.1'

When I provision my vagrant machine, I get the following error:

Error executing action `create` on resource 'mysql_database[my_database]'

Mysql2::Error
-------------
Lost connection to MySQL server at 'reading initial communication packet', system error: 110

PS: it works perfectly on bento/centos7.2

EDIT: Here is the database creation part:

# Install the MySQL client
mysql_client 'default' do
  action :create
end

# Configure the MySQL service
mysql_service 'default' do
  initial_root_password node['webserver']['database']['root_password']
  action [:create, :start]
end

# Install the mysql2 Ruby gem
mysql2_chef_gem 'default' do
  action :install
end

mysql_database node['webserver']['database']['db_name'] do
  connection(
    :host     => node['webserver']['database']['host'],
    :username => node['webserver']['database']['root_username'],
    :password => node['webserver']['database']['root_password']
   )
  action :create
end

EDIT 2: It doesn't really work on bento/centos7.2. It doesn't crash, but MySQL seems to be dead and running sudo systemctl start mysqld hangs.

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206

1 Answers1

0

I was over suggestion by the fact that I was using many new things (I'm also new to Chef) so I thought the problem came from a different source (vagrant, bad bersfile integration, something else).

Turns out I just didn't read the docs which clearly states:

Logging into the machine and typing mysql with no extra arguments will fail. You need to explicitly connect over the socket with mysql -S /var/run/mysql-foo/mysqld.sock, or over the network with mysql -h 127.0.0.1

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206