change default collation in phpmyadmin

后端 未结 8 840
野的像风
野的像风 2020-12-23 17:05

It seems to me that phpMyAdmin imports tables by default with collation latin1_swedish_ci, how i change this?

8条回答
  •  忘掉有多难
    2020-12-23 17:43

    This is not a phpMyAdmin question.

    Collations are part of recent MySQL releases, you must set the default collation of the server (or at least of the database) to change that behaviour.

    To convert already imported tables to UTF-8 you can do (in PHP):

    $dbname = 'my_databaseName';
    mysql_connect('127.0.0.1', 'root', '');
    mysql_query("ALTER DATABASE `$dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
    $res = mysql_query("SHOW TABLES FROM `$dbname`");
    while($row = mysql_fetch_row($res)) {
       $query = "ALTER TABLE {$dbname}.`{$row[0]}` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci";
       mysql_query($query);
       $query = "ALTER TABLE {$dbname}.`{$row[0]}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
       mysql_query($query);
    }
    echo 'all tables converted';
    

    Code snippet taken from here.

提交回复
热议问题