title: MySQL encoding from Latin-1 to UTF-8
body: <p>For a very long time i was suffering form the Latin-1 encoding in My Django web application DB causing this error when trying to select a matching string using LIKE :</p>
  
  <pre><code> -- UnicodeEncodeError:'latin-1' codec can't encode character--
  </code></pre>
  
  <p>i've tried every solution from setting <strong>(charset='utf8')</strong> in the connection to applying <strong>cursor.execute("set names 'utf8'")</strong> before my actual query but nothing seams to work. </p>
  
  <p>Until i came across this blog post: <a href="https://www.whitesmith.co/blog/latin1-to-utf8/" rel="nofollow noreferrer">https://www.whitesmith.co/blog/latin1-to-utf8/</a>
  about the encoding problem and it is the same problem that i have because when i looked in phpMyAdmin a saw that by default my DB i Latin-1 encoding:</p>
  
  <pre><code>chatbot_brain=&gt;utf8_general_ci
  information_schema=&gt;utf8_general_ci
  Total: 2=&gt;    latin1_swedish_ci
  </code></pre>
  
  <p>So, the solution is to dump the DB and change the description in the schema file:</p>
  
  <pre><code> # Login into your future database host to create a new database with an UTF-8 charset 
   $ mysql -h FUTURE_HOST -u FUTURE_USER -p
   mysql&gt; CREATE DATABASE `FUTURE_DB` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 
   # Flush the current database schema on the future host, replacing all CHARSET=latin1 occurrences along the way 
   mysqldump -h CURRENT_HOST -u CURRENT_USER -p CURRENT_DB --no-data --skip-set-charset --default-character-set=latin1 \  
   | sed 's/CHARSET=latin1/CHARSET=utf8/g' \ 
   | mysql -h FUTURE_HOST -u FUTURE_USER -p FUTURE_DB --default-character-set=utf8
   # Flush the current database data on the future host 
   mysqldump -h CURRENT_HOST -u CURRENT_USER -p --no-create-db --no-create-info --skip-set-charset --default-character-set=latin1 CURRENT_DB \  
   | mysql -h FUTURE_HOST -u FUTURE_USER -p FUTURE_DB --default-character-set=utf8 
  </code></pre>
  
  <p>Now i know what is the problem and the solution, But my question is how i can applied to my Django project-- Do i have to use my computer terminal and SSH session or is there any application of that?</p>
  
  <p>this is a sceen shot of my DB in phpmyAdmin:</p>
  
  <p><a href="https://ibb.co/dDu7D5" rel="nofollow noreferrer">https://ibb.co/dDu7D5</a></p>
  
  <p>Thank you</p>
  
  <p><strong>PS(I am using Django10 , Python3.5,Mysql,Webfaction sherd host)</strong></p>