change default collation in phpmyadmin

后端 未结 8 776
野的像风
野的像风 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.

    0 讨论(0)
  • 2020-12-23 17:43

    MySQL DB « change Collation Name of a Database|Table to utf8_general_ci inorder to support Unicode.

    Change Configuration settings file also


    XAMPP: uncomment UTF 8 Settings from the Configuration settings file « D:\xampp\mysql\bin\my.ini

    ## UTF 8 Settings
    #init-connect=\'SET NAMES utf8\'
    collation_server=utf8_unicode_ci
    character_set_server=utf8
    skip-character-set-client-handshake
    character_sets-dir="D:/xampp/mysql/share/charsets"
    

    For MySQL server to support UTF8 and the below line of code in file my.cnf

    ## UTF 8 Settings
    collation_server=utf8_unicode_ci
    character_set_server=utf8
    

    @see

    • XAMPP - Apache Virtual Host Setting
    • XAMPP security concept - Error 403,404
    0 讨论(0)
提交回复
热议问题