title: RMySQL encoding issue on Windows - Spanish Character ñ
body: <p>While using RMySQL::dbWriteTable function in R to write a table to MySQL on Windows I get an error message concerning the character [ñ].</p>
  
  <p>The simplified example is:</p>
  
  <pre><code>    table &lt;- data.frame(a=seq(1:3), b=c("És", "España", "Compañía"))
      table
  
   a        b
  1 1       És
  2 2   España
  3 3 Compañía
  
  
  db &lt;- dbConnect(MySQL(), user = "####", password = "####", dbname ="test", host= "localhost")
  
  RMySQL::dbWriteTable(db, name="test1", table, overwrite=T, append=F )
  
  Error in .local(conn, statement, ...) : 
    could not run statement: Invalid utf8 character string: 'Espa'
  </code></pre>
  
  <p>As you can see, there is no problem with the accents ("És") but there is with the ñ character ("España").</p>
  
  <p>On the other hand, there is no problem with MySQL since this query works fine:</p>
  
  <pre><code>INSERT INTO test.test1 (a,b)
  values (1, "España");
  </code></pre>
  
  <p>Things I have already tried previous to write the table:</p>
  
  <ol>
  <li><p>Encoding(x) &lt;- "UTF-8" for all table. </p></li>
  <li><p>iconv(x, "UTF-8", "UTF-8") for all table.</p></li>
  <li><p>Sent pre-query: dbSendQuery(db, "SET NAMES UTF8;")</p></li>
  <li><p>Change MySQL table Collation to: "utf-8-general, latin-1, latin-1-spanish...)</p></li>
  </ol>
  
  <p>*Tried "Latin-1" encoding and didn't work either. </p>
  
  <p>I have been looking for an answer to this question for a while with no luck.<br>
  Please help!</p>
  
  <p>Versions:</p>
  
  <p>MySQL 5.7.17</p>
  
  <p>R version 3.3.0</p>
  
  <p>Sys.getlocale()</p>
  
  <pre><code>[1] "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=C"
  </code></pre>
  
  <p>PS: Works fine in Linux environment but I am stuck with Windows in my current project :(</p>