问题
"MySQL server has gone away". Hmm.
I am using vagrant and chef to setup my virtual development environment. I'm almost there, but on the last step chef fails when attempting to execute my external db_setup.sql file. I can execute this same script by SSH'ing into the virtual server and it installs without difficulty.
This is my problem code (in cookbooks/database/recipies/mysql.rb file):
# Query a database from a sql script on disk
mysql_database 'run script' do
database_name 'my_db'
connection mysql_connection_info
retries 3
sql { ::File.open('/vagrant/db_setup.sql').read }
action :query
end
The file is 6.9mb and the error I receive when I run vagrant provision
is:
==> default: [2014-08-24T16:04:53-07:00] ERROR: mysql_database[run script]
(database::mysql line 50) had an error: Mysql::Error: MySQL server has gone away
For what it's worth, when I replace the db_setup.sql file with a smaller, simpler file that just creates a few empty tables, it executes without difficulty.
Any suggestions? Thank you in advance!
回答1:
Many, many things can cause this error. In my experience it's usually an SQL file of over 1MB, or, the wait_timeout in your servers my.cnf is set very low (sixty seconds) needs properly tuned. When deploying my.cnf try a wait_timeout 86400 and a max_allowed_packet of "enough" to import that file.
For example:
[mysqld]
wait_timeout = 86400
max_allowed_packet = 1GB
PS. I would not recommend this high of parameters in actual production.
回答2:
I worked around this issue by getting Chef to leverage the mysql command line tool instead of using Ruby to read the .sql
file.
来源:https://stackoverflow.com/questions/25477128/mysql-chef-database-recipe-fails-on-large-file