Open doganoo opened 2 years ago
Same issue here
I ran into this issue too. The resources should add a property: ctrl_socket or something like that to allow user to specify the socket. A workaround can be changing 'localhost' to '127.0.0.1' so mysql client connect via tcp.
Some news for this topic? How to solve this issue on MySQL 8.0?
@dkd-kaehm don't think so, I did not get any feedback since I created the issue
@doganoo Thanks for reply.
Following helped me:
after mysql_service -> start the server is not fully initialized and rejects the connection for mysql_database, mysql_user resources, so i added sleep 2
command to give a little bit more time for subsequent actions:
mysql_service 'default' do
version mysql_version
mysqld_options('default-authentication-plugin' => 'mysql_native_password')
initial_root_password root_password
action %i[create start]
end
# This does the trick for https://github.com/sous-chefs/mysql/issues/674
execute 'sleep' do
command 'sleep 2'
end
IMHO the mysql_service -> start action should wait for mysql service is really ready.
Here is two issues - incorrect socket location to use for MySQL8 (Tested on Rocky8 mysql-community-server-8.0.34) and bug inside resource when compiling 'ctrl' hash. Please see screenshot, this is from recipe with one 'mysql_user' resource. This is one operation but compare Control Hash and SQL for first and second requests.
mysql_user node['mysql']['admin']['username'] do
action [:create, :grant]
password node['mysql']['admin']['password']
database_name '*'
host 'localhost'
privileges [:all]
grant_option true
end
Function 'run_query' https://github.com/sous-chefs/mysql/blob/main/resources/mysql_user.rb#L67C7-L67C16 force to use host and port in the Control Hash, this leads to use cookbook default incorrect socket file in the 'sql_command_string' function https://github.com/sous-chefs/mysql/blob/main/libraries/helpers.rb#L360. In the same time 'load_current_value' function do not send host and port if they are not set https://github.com/sous-chefs/mysql/blob/main/resources/mysql_user.rb#L57-L58 and incorrect socket file path ommited in the result shell command, and it working fine.
:speaking_head: Foreword
Thank you for providing this awesome cookbook.
:ghost: Brief Description
When trying to use the mysql_database and mysql_user resources, Chef throws error with "Can't connect to local MySQL server through socket '/var/run/mysql/mysqld.sock".
Please notice I am not trying to connect on the shell within the Vagrant Box.
The Cookbook:
The my_cnf.erb
The kitchen.yml:
attributes/apparmor.rb:
:pancakes:
Cookbook Version: 11.0.0
Chef Workstation version: 21.11.679 Chef Infra Client version: 17.7.29 Chef InSpec version: 4.49.0 Chef CLI version: 5.4.2 Chef Habitat version: 1.6.420 Test Kitchen version: 3.1.1 Cookstyle version: 7.25.9
Steps To Reproduce
Steps to reproduce the behavior:
:police_car: Expected behavior
A running MySQL instance with the given user/database
Error:
Please let me know if you need additional information. Thank you in advance!