title: Fetching UTF-8 text from MySQL in R returns "????"
body: <p>I'm stuck trying to fetch UTF-8 text in a MySQL database from R.  I'm running R on OS X (tried both via the GUI and command line), where the default locale is en_US.UTF-8, and no matter what I try, the query result shows "?" for all non-ASCII characters.</p>
  
  <p>I've tried setting <code>options(encoding='UTF-8')</code>, <code>DBMSencoding='UTF-8'</code> when connecting via ODBC, setting <code>Encoding(res$str) &lt;- 'UTF-8'</code> after fetching the results, as well as 'utf8' variants of each of those, all to no avail.  Running the query from the command line mysql client shows the results correctly.</p>
  
  <p>I'm totally stumped.  Any ideas why it's not working, or other things I should try?</p>
  
  <p>Here's a fairly minimal test case:</p>
  
  <pre><code>$ mysql -u root
  mysql&gt; CREATE DATABASE test;
  mysql&gt; USE test;
  mysql&gt; CREATE TABLE test (str VARCHAR(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  Query OK, 0 rows affected (0.02 sec)
  
  mysql&gt; INSERT INTO test (str) VALUES ('こんにちは');
  Query OK, 1 row affected (0.00 sec)
  
  mysql&gt; select * from test;
  +-----------------+
  | str             |
  +-----------------+
  | こんにちは      |
  +-----------------+
  1 row in set (0.00 sec)
  </code></pre>
  
  <p>Querying the table in R using both RODBC and RMySQL shows "?????" for the str column:</p>
  
  <pre><code>&gt; con &lt;- odbcDriverConnect('DRIVER=mysql;user=root', DBMSencoding='UTF-8')
  &gt; sqlQuery(con, 'SELECT * FROM rtest.test')
      str
  1 ?????
  &gt; library(RMySQL)
  Loading required package: DBI
  &gt; con &lt;- dbConnect(MySQL(), user='root')
  &gt; dbGetQuery(con, 'SELECT * FROM rtest.test')
      str
  1 ?????
  </code></pre>
  
  <p>For completeness, here's my sessionInfo:</p>
  
  <pre><code>&gt; sessionInfo()
  R version 2.15.1 (2012-06-22)
  Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
  
  locale:
  [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
  [1] RMySQL_0.9-3 DBI_0.2-5    RODBC_1.3-6 
  </code></pre>