From 1cc07977c5bae4fd66ff1bf72b5adc938c54d961 Mon Sep 17 00:00:00 2001 From: Srinath M Date: Sun, 15 Dec 2013 21:47:10 -0500 Subject: [PATCH] Added [if not exists] to [create database] clause. this should avoid errors like: ERROR 1007 (HY000): Can't create database 'MyDB'; database exists This error can cause a multi-master replication to stop due to conflicting commands between nodes. For example, if the command create DB is run in different nodes and then they will send it in the replication logs to each other and then they will try to run them second time and fail. --- lib/puppet/provider/mysql_database/mysql.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/mysql_database/mysql.rb b/lib/puppet/provider/mysql_database/mysql.rb index ef95819..84f4463 100644 --- a/lib/puppet/provider/mysql_database/mysql.rb +++ b/lib/puppet/provider/mysql_database/mysql.rb @@ -31,7 +31,7 @@ Puppet::Type.type(:mysql_database).provide(:mysql, :parent => Puppet::Provider:: end def create - mysql([defaults_file, '-NBe', "create database `#{@resource[:name]}` character set #{@resource[:charset]} collate #{@resource[:collate]}"].compact) + mysql([defaults_file, '-NBe', "create database if not exists `#{@resource[:name]}` character set #{@resource[:charset]} collate #{@resource[:collate]}"].compact) @property_hash[:ensure] = :present @property_hash[:charset] = @resource[:charset]