title: How to Properly Set Variables (character_set_%) for Proper Cyrillic Leters Reading from MySQL in R
body: <p>I am experiencing the issue of unproper reading of cyrillic letters from MySQL table.</p>
  <p>I use the following code:</p>
  <pre><code>library(RMySQL)
  library(keyring)
  
  mydb = dbConnect(MySQL(), ...)
  dbReadTable(mydb, 'tregions2')
  </code></pre>
  <p>The table is read but cyrillic letters are substituted with question marks:</p>
  <pre><code>  id     regionname  iSOID administrativeCenter
  1  1 ????????? ???? RU-ALT              ???????
  </code></pre>
  <p>I started investigating into the issue.</p>
  <p>The result of the query <code>show variables like 'character_set_%';</code> in MySQL Workbench for the same user logged in on the same PC returns:</p>
  <pre><code>character_set_client    utf8mb4
  character_set_connection    utf8mb4
  character_set_database  utf8
  character_set_filesystem    binary
  character_set_results   utf8mb4
  character_set_server    utf8mb4
  character_set_system    utf8
  character_sets_dir  C:\Program Files\MySQL\MySQL Server 8.0\share\charsets\
  </code></pre>
  <p>But result of the query returned by R is different:</p>
  <pre><code>&gt; dbGetQuery(mydb, &quot;show variables like 'character_set_%'&quot;)
               Variable_name                                                         Value
  1     character_set_client                                                        latin1
  2 character_set_connection                                                        latin1
  3   character_set_database                                                          utf8
  4 character_set_filesystem                                                        binary
  5    character_set_results                                                        latin1
  6     character_set_server                                                       utf8mb4
  7     character_set_system                                                          utf8
  8       character_sets_dir C:\\Program Files\\MySQL\\MySQL Server 8.0\\share\\charsets\\
  </code></pre>
  <p>The locale variables of R are the following:</p>
  <pre><code>&gt; Sys.getlocale()
  [1] &quot;LC_COLLATE=Russian_Russia.1251;LC_CTYPE=Russian_Russia.1251;LC_MONETARY=Russian_Russia.1251;LC_NUMERIC=C;LC_TIME=Russian_Russia.1251
  </code></pre>
  <p>I tried to change character set and collation of the table in DB. Earlier setting cp1251 character set helped me to properly write the data into the database. But not now. I tried utf8/koi8r/cp1251 without any effect.</p>
  <p>Attempt to execute <code>Sys.setlocale(,&quot;ru_RU&quot;)</code> aborted with an error that it could not be executed.</p>
  <p>I am stuck. Could anyone give me an advise what else I should do?</p>