I am writing a chef script to automate setting dev environments. I can get a database created and grant privileges but I am trying to find out a way to import a mysql dump file into the database that has just been created.
My code for granting the access is
ruby_block "Execute grants" do
block do
require 'rubygems'
Gem.clear_paths
require 'mysql'
m = Mysql.new('localhost', "root", node[:mysql][:server_root_password])
m.query("GRANT ALL ON *.* TO 'root'@'10.0.0.1' IDENTIFIED BY '#{node[:mysql][:server_root_password]}'")
m.query('FLUSH PRIVILEGES')
end
end
and I was hoping I would be able to do the following query
#m.query("-u root -p root db_name < /project/db/import.sql")
but is just gives me an error.
I haven't done much Ruby so finding it hard to figure out. Anybody know how I can do this?