[chef] Re: Re: Can't set encoding on MySQL database


Chronological Thread 
  • From: Kevin Harvey < >
  • To:
  • Subject: [chef] Re: Re: Can't set encoding on MySQL database
  • Date: Mon, 21 Nov 2011 14:33:06 -0500

Joshua, thank you so much. I'm working on getting this in my recipe now. However, I first tried dropping in the brand new v 1.2.1 MySQL cookbook and got this error: "NoMethodError: undefined method `mysql_database' for #<Chef::Recipe:0xb6c7bf94>"

Is there a how to guide for upgrading cookbooks anywhere?

--
Kevin Harvey
Web Developer
615-686-8238
" target="_blank">



On Mon, Nov 21, 2011 at 12:49 PM, Joshua Timberman < "> > wrote:
Hello!

On Nov 21, 2011, at 6:33 AM, Kevin Harvey wrote:

> "databases": {
>   "_default": {
>     "encoding": "utf8",
>     "username": "django",
>     "adapter": "mysql",
>     "port": "3306",
>     "database": "django_production",
>     "password": "awesome_password"
> }
>
> However, this doesn't seem to get picked up, as after the server is created I try this:
>
> ssh ">
>
> mysql -u root -p
> mysql> use django_production;
> mysql> SHOW VARIABLES LIKE "character\_set\_database";
> +------------------------+--------+
> | Variable_name          | Value  |
> +------------------------+--------+
> | character_set_database | latin1 |
> +------------------------+--------+
> 1 row in set (0.00 sec)
>
> I took a look at cookbooks/database/master.rb, and edited as such to try to get the encoding added in, starting at line 84:
>
> ...
>     mysql_database "create #{db['database']}" do
>       host "localhost"
>       username "root"
>       password root_pw
>       database db['database']
>       encoding db['encoding']     # I added this line
>       action [:create_db]
>     end
> ...

The 'encoding' in the application data bag examples is primarily there from the application::rails recipe, and it is not used in the local_settings.py file. It also is not used in the mysql_database resource, which is why adding the `encoding db['encoding']` line didn't do anything. It appears you're using an older version of the mysql cookbook, where the mysql_database resource was defined. The actual query is:

   action :create_db do
     ...
         db.query("create database #{new_resource.database}")
     ...
   end

It simply sends the `create database` query, but does not specify any encoding. FYI, this provider is moved to the `database` cookbook in newer versions of both. I created a COOK ticket to track this:

http://tickets.opscode.com/browse/COOK-841

For now, you should be able to work around this issue by adding this to cookbooks/mysql/resources/database.rb:

   attribute :encoding, :kind_of => String, :default => "utf8"

And modify the db.query line in the cookbooks/mysql/providers/database.rb under the create_db action to:

         db.query("create database #{new_resource.database} CHARACTER SET = '#{new_resource.encoding}'")

This will default to utf8.

--
Opscode, Inc
Joshua Timberman, Technical Program Manager
IRC, Skype, Twitter, Github: jtimberman





Archive powered by MHonArc 2.6.16.

§