title: Convert a MySQL database from latin to UTF-8
body: <p>I am converting a website from ISO to UTF-8, so I need to convert the MySQL database too.</p>
  
  <p>On the Internet, I read various solutions, I don't know which one to choose.</p>
  
  <p>Do I really need to convert my varchar columns to binary, then to UTF-8 like that:</p>
  
  <pre><code>ALTER TABLE t MODIFY col BINARY(150);
  ALTER TABLE t MODIFY col CHAR(150) CHARACTER SET utf8;
  </code></pre>
  
  <p>It takes a long time to do that for each column, of each table, of each database.</p>
  
  <p>I have 10 databases, with 20 tables each, with around 2 - 3 varchar columns (2 queries each column), this gives me around <strong>1000 queries to write</strong>! How to do it?</p>
  
  <p><strong>Resolved</strong> :
  I post the code that I have used:</p>
  
  <pre><code>PASSWORD=""
  db=$1
  
  mysqldump --password=$PASSWORD --set-charset --skip-set-charset --add-drop-table --databases "$db" &gt; /home/dev/backup/bdd.sql
  
  QUERY="ALTER DATABASE \`$db\` DEFAULT CHARACTER SET utf8;"
  mysql --password=$PASSWORD --database "$db" -e "$QUERY"
  
  mysql --password=$PASSWORD --default-character-set=utf8 &lt; /home/dev/backup/bdd.sql
  </code></pre>
  
  <p>See the answer below for more information.</p>