Unable to connect to the mysql database server

I used the following lines in my cookbook

mysql_service ‘default’ do
bind_address '0.0.0.0’
initial_root_password 'password’
action [:create, :start]
end

And here is the my.cnf

Chef generated my.cnf for instance mysql-default

[client]
default-character-set = utf8
port = 3306
socket = /run/mysql-default/mysqld.sock

[mysql]
default-character-set = utf8

[mysqld]
user = mysql
pid-file = /run/mysql-default/mysqld.pid
socket = /run/mysql-default/mysqld.sock
bind-address = 0.0.0.0
port = 3306
datadir = /var/lib/mysql-default
tmpdir = /tmp
log-error = /var/log/mysql-default/error.log
!includedir /etc/mysql-default/conf.d

[mysqld_safe]
socket = /run/mysql-default/mysqld.sock

But I am unable to login:

mysql -u mysql -p
Enter password:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket
’/var/run/mysqld/mysqld.sock’

I have also tried login ‘root’ and it did not work either.

What did I miss in my cookbook?

Cheers, Tony

Looking at the error message it seems it's looking for socket file in the
wrong place.
Cheers
Marco
Il 15/feb/2015 12:52 "Anthony Kong" anthony.hw.kong@gmail.com ha scritto:

I used the following lines in my cookbook

mysql_service 'default' do
bind_address '0.0.0.0'
initial_root_password 'password'
action [:create, :start]
end

And here is the my.cnf

Chef generated my.cnf for instance mysql-default

[client]
default-character-set = utf8
port = 3306
socket = /run/mysql-default/mysqld.sock

[mysql]
default-character-set = utf8

[mysqld]
user = mysql
pid-file = /run/mysql-default/mysqld.pid
socket = /run/mysql-default/mysqld.sock
bind-address = 0.0.0.0
port = 3306
datadir = /var/lib/mysql-default
tmpdir = /tmp
log-error = /var/log/mysql-default/error.log
!includedir /etc/mysql-default/conf.d

[mysqld_safe]
socket = /run/mysql-default/mysqld.sock

But I am unable to login:

mysql -u mysql -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock'

I have also tried login 'root' and it did not work either.

What did I miss in my cookbook?

Cheers, Tony

On Sun, 15 Feb 2015, Anthony Kong wrote:

But I am unable to login:

mysql -u mysql -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock'

Seems like your mysql binary assumes the socket is in this location
whereas your recipe set up my.cnf to have the socket in
/run/mysql-default/mysqld.sock .

  • Julian

Previously I have used the other cookbook 'mysqld' in another vagrantfile:

config.vm.provision "chef_zero" do |chef|
chef.add_recipe 'mysqld'
chef.json = {
:mysqld => {
:root_password => "password"
}
}
end

and it just installed the client and server without any issue.

The official mysql cookbook apparently does not work out of the box :frowning:

On Mon, Feb 16, 2015 at 3:11 AM, Julian C. Dunn jdunn@aquezada.com wrote:

On Sun, 15 Feb 2015, Anthony Kong wrote:

But I am unable to login:

mysql -u mysql -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock'

Seems like your mysql binary assumes the socket is in this location
whereas your recipe set up my.cnf to have the socket in
/run/mysql-default/mysqld.sock .

  • Julian

It works, you just need to specify the path to the socket, or connect
over the network.

From the README faq section:

mysql -h 127.0.0.1 -Ppassword

-s

The approach of using command line passwords for mysql access causes problems with MySQL 5.6, or at least that from Percona. It whinges unpreventably about passwords in the command line, and obscures other more relevant error messages.

I've worked around it by setting "MYSQL_PWD" environment variables for relevant users to contain the relevant password, or setting a relevant $HOME/.my.cnf and relying on that managed with a local cookbook with more protected password data, instead. This can also help prevent including plain-text MySQL passwords in monitoring and backup configurations for MySQL, or in git managed central environments where passwords are sensitive. The default use of plain text passwords by the mysql cookbook is actually a security issue for setting up new servers.

Nico Kadel-Garcia
Lead DevOps Engineer
nkadel@skyhookwireless.com

-----Original Message-----
From: Sean OMeara [mailto:someara@chef.io]
Sent: Sunday, February 15, 2015 3:28 PM
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Unable to connect to the mysql database server

It works, you just need to specify the path to the socket, or connect over the
network.

From the README faq section:

mysql -h 127.0.0.1 -Ppassword

-s

Thanks everyone for your input!

Tony Kong
blog: www.ahwkong.com
linkedin: www.linkedin.com/in/anthonykong

Don’t EVER make the mistake that you can design something better than what
you get from ruthless massively parallel trial-and-error with a feedback
cycle. That’s giving your intelligence much too much credit.

  • Linus Torvalds

On Wed, Feb 18, 2015 at 4:24 AM, Nico Kadel-Garcia <
nkadel@skyhookwireless.com> wrote:

The approach of using command line passwords for mysql access causes
problems with MySQL 5.6, or at least that from Percona. It whinges
unpreventably about passwords in the command line, and obscures other more
relevant error messages.

I've worked around it by setting "MYSQL_PWD" environment variables for
relevant users to contain the relevant password, or setting a relevant
$HOME/.my.cnf and relying on that managed with a local cookbook with more
protected password data, instead. This can also help prevent including
plain-text MySQL passwords in monitoring and backup configurations for
MySQL, or in git managed central environments where passwords are
sensitive. The default use of plain text passwords by the mysql cookbook
is actually a security issue for setting up new servers.

Nico Kadel-Garcia
Lead DevOps Engineer
nkadel@skyhookwireless.com

-----Original Message-----
From: Sean OMeara [mailto:someara@chef.io]
Sent: Sunday, February 15, 2015 3:28 PM
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Unable to connect to the mysql database
server

It works, you just need to specify the path to the socket, or connect
over the
network.

From the README faq section:

mysql -h 127.0.0.1 -Ppassword

-s