Skip to main content

FIX - phpmysql error - #1273 - #1273 - Unknown collation: 'utf8mb4_general_ci' - with sql file only

How to FIX - phpmysql error - #1273 - #1273 - Unknown collation: 'utf8mb4_general_ci'

Why does it happens?

The utf8mb4_unicode_ci is supported only on mysql servers 5.5.3+ and you will not be available on older servers. That's all.










The worst solution

if you have only an sql file you can TRY to

... COLLATE utf8mb4_unicode_ci
to
utf8_general_ci

but it's NOT SAFE because you can probably have problems with the encoding!!! I've tested and it also works but really don't know if there can be consequences.


The best solution


Export from the original database in utf8_general_ci or, if you just have the sql, Import your data in a newer mysql server (5.5.3+) and export again with utf8_general_ci!


Another way to do it
If you want to operate on a live database run this sql for each table.

ALTER TABLE name-of-table CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci


Sample (crappy) php code


<?php
 $dbuser = 'test2';
 $dbpassword = 'test2';
 $dbhost = 'localhost';
 $dbname = 'test2';
    $dbconn=mysqli_connect($dbhost, $dbuser, $dbpassword);
    mysqli_select_db($dbconn,$dbname);
    $mydata=mysqli_query($dbconn, 'show tables');
    while($mytables = mysqli_fetch_array($mydata)) {
       foreach ($mytables as $myktable => $mytable) {
        mysqli_query($dbconn, "ALTER TABLE $mytable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");

       }

    }
?> 
 
 
and then export your data.




This happened with several cms like wordpress, joomla, magento, opencart, drupal, smf forums, etc.

It's not a problem related to the scripts!

Comments

Popular posts from this blog

Moodle 3.8.1+ - path leak via errors in several files

Moodle 3.8.1+ ----------------------------------------------- File: admin/mailout-debugger.php #!/usr/bin/php Notice : Disabled. in \admin\mailout-debugger.php on line 73 File: admin/settings/appearance.php Notice : Undefined variable: hassiteconfig in \admin\settings\appearance.php on line 10 Fatal error : Uncaught Error: Call to undefined function has_any_capability() in \admin\settings\appearance.php:10 Stack trace: #0 {main} thrown in \admin\settings\appearance.php on line 10 File: admin/settings/badges.php Notice : Undefined variable: hassiteconfig in \admin\settings\badges.php on line 30 Fatal error : Uncaught Error: Call to undefined function has_any_capability() in \admin\settings\badges.php:30 Stack trace: #0 {main} thrown in \admin\settings\badges.php on line 30 File: admin/settings/courses.php Notice : Undefined variable: hassiteconfig in \admin\settings\courses.php on line 32 Fatal error : Uncaught Error: Call to undefined function

2022 - Remove (the too many) Ads from Memu launcher

Simple method Download from pureapk "MEmu Launcher2" ex: MEmu Launcher2_v6.0.9_apkpure.com Install "System app remover" (root) remove from system apps the "memu launcher 2" import the "purified" MEmu Launcher2 apk with the Memu utility ("apk" on the right toolbar) Longer method Install "Export Apk" Export the memu launcher2  Install purify https://github.com/echo-devim/purify/raw/master/Purify.apk use purify with the exported memu launcher 2 Install "System app remover" (root) remove from system apps the "memu launcher 2" import the "purified" MEmu Launcher2 apk with the Memu utility ("apk" on the right toolbar)