Skip to content

Instantly share code, notes, and snippets.

@ChriStef
ChriStef / mysql-alter-tables.php
Last active July 11, 2020 09:59 — forked from michael-e/mysql-alter-tables.php
Loop over all tables of a MySQL database and convert them to `utf8` character set. Also make them use `utf8_unicode_ci` collation. You are encouraged to use the PHP CLI (i.e. run the script from the command line), simply because it may take a while. (On the webserver the script may timeout.)
<?php
// configuration
$link = mysqli_connect("host","username","password");
mysqli_select_db($link, "database");
// do it
$resource = mysqli_query("SHOW TABLES");
while ($row = mysqli_fetch_array($resource)) {
$table = $row[0];