title: How to execute MySQL in Chef Ruby block
body: <p>Ok, I have a Recipe that calls Opscode MySQL cookbook.</p>
  
  <p>I can create the database but I am unsure how to create a MySQL user with read/write privileges in the Chef Recipe.</p>
  
  <p>Here is my recipe:</p>
  
  <pre><code>include_recipe 'percona' #this is an example
  
  mysql_secret = Chef::EncryptedDataBagItem.load_secret("#{node[:percona][:encrypted_data_bag_secret_file]}")
  mysql_creds = Chef::EncryptedDataBagItem.load("passwords", "mysql", mysql_secret)
  pdns_password='1H@t3D@taB@G$!'
  mysql_connection_info = {
    :host =&gt; "127.0.0.1",
    :username =&gt; 'root',
    :password =&gt; mysql_creds["root"]
  }
  
  #
  # Only write to master pdb01
  #
  if node.name =~ /pdb01/
      dbs=['serv']
      # Create application database
      dbs.each do |db|
          ruby_block "create_#{db}_db" do
            block do
              %x[mysql -uroot  -e "CREATE DATABASE #{db};"]
            end
            not_if "mysql -u root  -e \"SHOW DATABASES LIKE '#{db}'\" | grep #{db}";
            action :create
          end
      end
  end
  # Grant mysql privileges
  dbs.each do |db|
      ruby_block "add_servo_#{db}permissions" do
          block do
            %x[mysql -u root  -e "GRANT SELECT,INSERT,UPDATE,DELETE \
              ON #{db}.* TO 'serv'@'127.0.0.1' IDENTIFIED BY '#{servo_password}';"]
              end
              not_if "mysql -u root  -e \"SELECT user, host FROM mysql.user\" | \
                grep serv | grep #{db}"
              action :create
          end
  end
  #
  # Create pdb02 slave replication
  #
  
  if node.name =~ /pdb02/
      dbs=['serv','serv_app'
      # Create application database
      dbs.each do |db|
          ruby_block "create_#{db}_db" do
            block do
              %x[mysql -uroot  -e "CREATE DATABASE #{db};"]
            end
            not_if "mysql -u root  -e \"SHOW DATABASES LIKE '#{db}'\" | grep #{db}";
            action :create
          end
      end
      dbs.each do |db|
          ruby_block "add_serv_#{db}permissions" do
              block do
                %x[mysql -u root  -e "GRANT SELECT,INSERT,UPDATE,DELETE \
                  ON #{db}.* TO 'repl'@'127.0.0.1' IDENTIFIED BY 'replpass';"]
                 GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'replpass';
                  end
                  not_if "mysql -u root  -e \"SELECT user, host FROM mysql.user\" | \
                    grep repl | grep #{db}"
                  action :create
              end
      end
  end
  </code></pre>
  
  <p><strong>AND - it fails here</strong>:</p>
  
  <pre><code>   SyntaxError
     -----------
     /tmp/kitchen/cache/cookbooks/cb-dataBases/recipes/pdb.rb:55: syntax error, unexpected tIDENTIFIER, expecting ']'
  
         dbs.each do |db|
            ^
     /tmp/kitchen/cache/cookbooks/cb-dataBases/recipes/pdb.rb:69: syntax error, unexpected '.'
     ...  GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY...
     ...                               ^
     /tmp/kitchen/cache/cookbooks/cb-dataBases/recipes/pdb.rb:69: `@'' is not allowed as an instance variable name
     /tmp/kitchen/cache/cookbooks/cb-dataBases/recipes/pdb.rb:69: syntax error, unexpected $end, expecting keyword_end
     ...ICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'replpass'; 
     ...                               ^
  </code></pre>
  
  <p>What am I doing wrong?</p>