Problem/Motivation
The Database Configuration page does not display a version requirement error when attempting to install on a MySQL server that does not support utf8mb4 charset. The install tasks should display the version requirement error instead of throwing the Exception.
SQLSTATE[42000]: Syntax error or access violation: 1115 Unknown character set: 'utf8mb4'.
The root cause of this issue is that the connection throws an exception with a server error code: "1115 Unknown character set: utf8mb4" instead of what the mysql driver is expecting, which is a client error code: "2019 Can't initialize character set 'utf8mb4' (path: 'utf8mb4')".
Proposed resolution
Display the version requirement error when the Exception has the 1115 error code in \Drupal\Core\Database\Driver\mysql\Install\Tasks
This will cause the appropriate error message to be displayed to the user and reduce confusion.
Remaining tasks
- Determine if the mysql driver should even care about the client error code.
- Write a patch that catches the 1115 server error code (as well or instead).
- Manually test patch on systems with unsupported version of MySQL.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #2
Liam MorlandComment #3
stefan.r CreditAttribution: stefan.r commentedComment #4
stefan.r CreditAttribution: stefan.r commentedWhich mysql versions are you using? (server / libmysqlclient?) And which version of drupal 8?
Comment #5
shazbot28 CreditAttribution: shazbot28 as a volunteer commentedI'm getting the same error due to the MySQL server version installed but no notification said so. Had to look at the install requirements to see that it required 5.5.3 or higher. Testing with webhost Dreamhost and they have 5.1.56 as a standard so I requested to have the SQL database moved to their beta testing MySQL 5.6.
Drupal: 8.0.0-rc1
MySQL Server version: 5.1.56
Comment #6
stefan.r CreditAttribution: stefan.r commentedComment #7
Liam MorlandI'm running 8.0.x at revision 1672445, which is 2 commits before -rc1. MySQL 5.1. mysqlnd 5.0.11.
Comment #8
oriol_e9gMySQL 5.5.3 is the minium that ini_charset() could just force it to utf8mb4
Comment #9
catchMoving version back to 8.0.x which is where it will get fixed.
Comment #10
mradcliffeI updated the issue summary with details about the task.
I do not know if it is still necessary to have the client error code or if we could just replace it with the server error code. Once that is confirmed, then the appropriate patch can be written fairly trivially.
It is also possible to write a test if we want to mock Connection for the driver to return an error message and try to run the install task for the driver.
Comment #11
mradcliffeChanging component to mysql driver.
Comment #12
sumthief CreditAttribution: sumthief as a volunteer and at DrupalJedi commentedHi. I've tried to make a patch for this issue.
Comment #13
stefan.r CreditAttribution: stefan.r commentedUnder what circumstances does the error in #7 appear? I think the problem is the server version rather than the libmysqlclient version? #7 used mysqlnd so the problem there was not libmysqlclient.
We already have some logic in the installer that makes it fall back to utf8, we should probably catch the mentioned exception and use that instead.
Comment #14
Liam MorlandI was running MySQL 5.1. When I upgraded that, the problem went away.
Comment #15
stefan.r CreditAttribution: stefan.r commentedComment #16
sumthief CreditAttribution: sumthief as a volunteer and at DrupalJedi commentedThere are updated patch #15. Tested under Windows + MySQL 5.1.67.
Comment #17
stefan.r CreditAttribution: stefan.r commentedAh that's right, we need to check for both!
Should we add a constant for SQLSTATE error code 42000? (Syntax error or access violation)
Should we change this to "Driver-specific error code for "Unknown character set" error."?
see https://secure.php.net/manual/en/pdo.errorinfo.php
Comment #18
sumthief CreditAttribution: sumthief as a volunteer and at DrupalJedi commentedOne more patch update. With help of @stefan.r.
Comment #19
stefan.r CreditAttribution: stefan.r commentedLooks great to me! @Liam Morland or anyone else could you please manually test?
Comment #20
Liam MorlandTesting manually, it works fine.
Attached is a re-roll which uses Tasks::minimumVersion() instead of a hard-coded minimum version in the error message.
It would probably be better if the message "The database server version 5.1.72 is less than the minimum required version 5.5.4." was above the message about utf8mb4 character encoding, though I can see the difficulty in doing this.
Comment #21
stefan.r CreditAttribution: stefan.r commentedThanks! Could we re-upload #18? This change would be out of scope here, it's fine to keep it hardcoded as this is about utf8mb4 support which is 5.5.3 always, and it'd need an @placeholder rather than a :placeholder.
Comment #22
sumthief CreditAttribution: sumthief as a volunteer and at DrupalJedi commentedSure we can re-upload patch #18. But why we should leave minimal MySQL server version hardcoded? I think during Drupal 8 life cycle it won't be changed to higher version that will not reflect really minimal version.
Comment #23
sumthief CreditAttribution: sumthief as a volunteer and at DrupalJedi commentedComment #24
Liam MorlandWhen the minimum increases again, I wouldn't want someone to upgrade to 5.5.3 to clear the charset issue and then be hit with another error stating they need to upgrade again. However, I do see that this is strictly a separate issue.
Comment #25
stefan.r CreditAttribution: stefan.r commentedThanks! In case the minimum changes, the /whole/ message will need to be rewritten. "a version that supports utf8mb4, such as (new minimum version)", wouldn't be correct... so, RTBC'ing re-uploaded #18.
Comment #26
stefan.r CreditAttribution: stefan.r commentedSeems it hasn't been re-uploaded yet, setting back to NW
Comment #27
sumthief CreditAttribution: sumthief as a volunteer and at DrupalJedi commentedYeah, looks like it'll be better hardcoded. Re-uploading #18 and RTBCing according to #25.
Comment #28
catchComment #29
Liam Morland#27 Looks good. Thanks.
Comment #30
mradcliffeI'm not sure if the line wrapping here is what is done in other places in core.
I looked at the coding standards to make sure, but there are no coding standards with regard to wrapping conditions on the next line so this technically does not need to be fixed.
Comment #31
stefan.r CreditAttribution: stefan.r commented#30 we do do it in a few places if you grep for
' ||'
, let's have a core committer it fix it on commit if necessary.Comment #32
Liam MorlandThe Line length and wrapping section states "Conditions should not be wrapped into multiple lines". Attached is a patch identical to #27, but with the condition on one line.
Comment #33
stefan.r CreditAttribution: stefan.r commentedLooks good, thanks
Comment #35
webchickAwesome, thanks a lot for this. I've hit this before, I think on DreamHost and it's a totally inscrutable problem.
Talked this over with the core committers, and we agreed that this is a viable RC target. It's a non-invasive fix, with a lot of impact for users.
Committed and pushed to 8.0.x. Thanks!