Mysql - 将排序规则更改为UFC-8 general-ci(用于表和列)

时间:2017-03-31 15:14:49

标签: php mysql

默认情况下,我的所有表和列都处于一些奇怪的排序规则(latin1_swedish_ci)。我想将它们更改为" utf8_unicode_ci"但由于我有100个表和许多列,我想用一个命令来做这个。有谁知道怎么做?

1 个答案:

答案 0 :(得分:0)

您可以在PHP

中运行此功能
$con = mysql_connect('server_name','user_name','password');
mysql_select_db('database_name');
$result = mysql_query('show tables');
while($tables = mysql_fetch_array($result)) {
        foreach ($tables as $key => $table_name) {
          mysql_query('alter table $table_name convert to character set utf8 collate utf8_general_ci');
}}