Details
-
Type:
Bug
-
Status: Development in progress
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: 3.7.5, 3.8.2
-
Fix Version/s: None
-
Component/s: Database SQL/XMLDB
-
Labels:None
-
Database:MySQL
-
Testing Instructions:
-
Affected Branches:MOODLE_37_STABLE, MOODLE_38_STABLE
-
Pull from Repository:
-
Pull Master Branch:m39_MDL-68531_MySQL_Tool_Collation_Hyphen_DB_Name
Description
Moodle Version: 3.7.5
mariadb: 10.1.44
System: Ubuntu 18.04
I try to convert database encoding from utf8 to utf8mb4 with this manual: https://docs.moodle.org/37/en/MySQL_full_unicode_support
With one Installation no problem with the other I get an error:
/opt/plesk/php/7.3/bin/php admin/cli/mysql_collation.php --collation=utf8mb4_unicode_ci
Converting database to 'utf8mb4_unicode_ci' for ********:
Error: Tried to alter the database with no success. Please try manually changing the database
                   to the new collation and character set and then run this script again.
I have take a look on the code:
https://github.com/moodle/moodle/blob/master/admin/cli/mysql_collation.php#L122
If i change
$sql = "ALTER DATABASE $CFG->dbname DEFAULT CHARACTER SET $charset DEFAULT COLLATE = $collation";
to
$sql = "ALTER DATABASE `$CFG->dbname` DEFAULT CHARACTER SET $charset DEFAULT COLLATE = $collation";
Now it works. The Database name must be escaped with ``.