title: How to migrate MySQL database from Latin-1 to UTF-8?
body: <p>I have a MySQL Database (<code>myDB</code>; ~2GB in size) with 4 Tables (<code>tab1</code>, <code>tab2</code>, <code>tab3</code>, <code>tab4</code>). Currently, the data that is stored in the tables was added using the charset <code>ISO-8859-1</code> (i.e. <code>Latin-1</code>).</p>
  
  <p>I'd like to <strong>convert</strong> the data in all tables to <code>UTF-8</code> and use <code>UTF-8</code> as default charset of the tables/database/columns.</p>
  
  <p>On <a href="https://blogs.harvard.edu/djcp/2010/01/convert-mysql-database-from-latin1-to-utf8-the-right-way/" rel="nofollow noreferrer">https://blogs.harvard.edu/djcp/2010/01/convert-mysql-database-from-latin1-to-utf8-the-right-way/</a> I found an interesting approach:</p>
  
  <pre><code>mysqldump myDB | sed -i 's/CHARSET=latin1/CHARSET=utf8/g' | iconv -f latin1 -t utf8 | mysql myDB2
  </code></pre>
  
  <p>I haven't tried it yet, but are there any caveats?</p>
  
  <p><strong>Is there a way to do it directly in the MySQL shell?</strong></p>
  
  <p>[EDIT:]</p>
  
  <p>Result of <code>SHOW CREATE TABLE messages;</code> after running <code>ALTER TABLE messages CONVERT TO CHARACTER SET utf8mb4;</code></p>
  
  <pre><code>CREATE TABLE `messages` (
    `number` int(11) NOT NULL AUTO_INCREMENT,
    `status` enum('0','1','2') NOT NULL DEFAULT '1',
    `user` varchar(30) NOT NULL DEFAULT '',
    `comment` varchar(250) NOT NULL DEFAULT '',
    `text` mediumtext NOT NULL,
    `date` int(11) NOT NULL DEFAULT '0',
    PRIMARY KEY (`number`),
    KEY `index_user_status_date` (`user`,`status`,`date`)
  ) ENGINE=InnoDB AUTO_INCREMENT=3285217 DEFAULT CHARSET=utf8mb4
  </code></pre>