Bug #102300 In the Workbench Confirming Server Status will cause RuntimeError
Submitted: 19 Jan 2021 23:10 Modified: 16 Apr 2021 7:23
Reporter: Naoya Eguchi Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Workbench: Administration Severity:S3 (Non-critical)
Version:8.0.23, 8.0.25, 8.0.27, 8.0.29, 8.0.32, 8.0.33 OS:Windows (version 10)
Assigned to: CPU Architecture:Any
Tags: In the Workbench, Server Status can not see also it clash the workbench

[19 Jan 2021 23:10] Naoya Eguchi
Description:
In the Workbench Confirming Server Status will cause RuntimeError and clash the workbench. After i upgraded the all MySQL Community products from v8.0.22 to v8.0.23.

How to repeat:
1.Downloads MySQL Community Installer 8.0.23.
※Windows (x86, 32-bit), MSI Installer.
2.Install MySQL as development mode.
3.Start MySQL Server.
4.Open the MySQL workbench.
5.At the Wellcome window, Connect to mysql(Local instance)
6.At the "Navigator", Click "Administration tab", then click "Server Status".
7.Error dialog has shown with below message,
 Cound not acquire management address for administration.
 RuntimeError: Unable to execute command chcp.
 Please make sure that the C:\Windows\System32 directory is in your PATH 
 enviroment variable.

8.In the message dialog press "cancel" button will crash the workbench.

※I checked, enviroment variable is set correctly.
※Also I tried uninstall all MySQL and installed as a new but same error occurs.
[20 Jan 2021 13:20] MySQL Verification Team
Hello Naoya Eguchi,

Thank you for the bug report.
I tried to reproduce your issue on windows 10 with workbench 8.0.23 but I am not seeing any issues at my end. 

Regards,
Ashwini Patil
[20 Jan 2021 13:23] MySQL Verification Team
8.0.23 test results

Attachment: 102300_test_results.PNG (image/png, text), 289.64 KiB.

[21 Jan 2021 0:56] Naoya Eguchi
Hello Ashwini Patil

Thanks you for quick reply and confirmation.

OK then it may be my enveroment problems, 
If I found a reason then, I will add comment.
[25 Jan 2021 12:19] Florent Conta
Hello,

I'm experiencing exactly the same issue after moving from Workbench 8.0.22 to Workbench 8.0.23.

My environment Path variable is correctly set and I can access chcp in the Windows 10 PowerShell.
I haven't found any workaround yet. This really looks like a regression in Workbench.
[25 Jan 2021 16:22] chelin jean-louis
Bonjour,
je viens de réinstaller mon serveur en version 8.0.23 et j'ai l'erreur :
unable to execute command chcp please make sure that the C\Windows\System32 directory is in your PATH environment variable

il est présent dans mon PATH !!!!
[16 Apr 2021 7:23] MySQL Verification Team
I hit the same problem on Windows 10, MySQL Server 8.0.23, and WB 8.0.23 combination.
[16 Apr 2021 7:48] MySQL Verification Team
Bug #103339 marked as duplicate of this one.
[16 Apr 2021 8:04] MySQL Verification Team
To workaround the problem, change the system locale to English. To change the
system locale:

* Open language settings
* Click "Administrative language settings" at the right top of the Window
* Click "Change system locale"
* Select English (United States) for example
* Click OK
* Restart the system
[16 Apr 2021 8:05] MySQL Verification Team
The workaround above is not affordable, nor acceptable in many cases for compatibility reasons. Even if WB runs well, other application may face charset problems.
[16 Apr 2021 18:15] Marco Fillion
Woah !

I have switch to English(US) and the problem is gone.

Please, take consideration multi-languages.

Thank you !
[17 Apr 2021 7:16] Florent Conta
Hi,

Thank you for your answer.
Unfortunately, changing the system locale is not an option in my case. It would be great that any system locale is supported by WorkBench, as it was before version 8.0.23.
[20 Apr 2021 5:33] MySQL Verification Team
Hi!

It was my mistake. The work around is changing UI language, not system locale. I changed both, and I thought the wrong one as a work around. Try to use English UI.

Thanks.
[20 Apr 2021 8:25] Florent Conta
Hi!
This new workaround may be fully acceptable for a production server. 
For the development computers on which I installed WB, I prefer sticking to WB 8.0.22 until the bug is fixed. Now that you identified the cause of the bug, do you have a target version for the bug fix?
Thanks
[28 May 2021 10:51] MySQL Verification Team
Bug #103838 marked as duplicate of this one
[3 Aug 2021 15:00] Karen Arzumanyan
I have the same error. Changing the system locale is unacceptable.
Please correct the error. 
Windows 7 Pro x64 (Russian Local) + MySQL Community Server 8.0.26.0 x64
[3 Aug 2021 20:43] MySQL Verification Team
Notice that Windows 7 it's an OS not supported;

https://www.mysql.com/support/supportedplatforms/database.html
[5 Sep 2021 16:47] 真也 岡野
I am using MySQL Workbench 8.0.26, same error occurs.

My enviroment is..

* Windows 10 Home
* Locale: Japanese

I can not change the locale my environment.
[8 Nov 2021 10:47] CANN Christophe
* MySQL Workbench 8.0.27
* Windows 10 Pro
* Locale fr-FR

Same error and changing the locale environment variable is not possible in my case.
Please take multilingual settings into account.
Thank you
[30 Jan 2022 17:58] Pat Sam
* MySQL Workbench 8.0.28
* Windows 11 Pro
* Locale: French

First of all, do not focus on the error message mentioning "Please make sure that the C:\Windows\System32 directory is in your PATH environment variable.". It is a generic report on all failure cases, even when the command is run and there is a problem in the parsing of its result.

There are two fixes to have a working Workbench. Both are related to stream encoding.

Fix 1
The current code supposes that the output of the chcp command is in utf8. When the UI language is English, it may be the case but it doesn't really matter because the output is probably just ordinary ascii characters (so no special character that would need an encoding).
The problem is for some non-english languages, that have some non-ordinary characters.
Let's take the example of French. The output has a no-break space, as seen in the binary representation:
b'Page de codes active\xa0: 437\r\n'
This is not utf8 (it would be \xc2\xa0), but more probably a cp1252 encoding (usual default on Windows).

To fix the problem, patch the following file as indicated:
C:\Program Files\MySQL\MySQL Workbench 8.0\workbench\os_utils.py
@@ -353,7 +353,9 @@
             # Note that self._command contains the internal command so EXEC
             # and self._args is the real OS command to be executed
             # Executes the command, reading the output from the PIPE
-            process = subprocess.Popen(command, stdin = subprocess.PIPE, encoding="utf-8", stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell=True)
+            # psam fix 30/01/22
+            # process = subprocess.Popen(command, stdin = subprocess.PIPE, encoding="utf-8", stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell=True)
+            process = subprocess.Popen(command, stdin = subprocess.PIPE, text=True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell=True)
 
             # Sends all the command output to the listener
             if output_handler:

Note: encoding="locale" would be a solution as well but this value is introduced in Python 3.10 and the python distribution embedded in WB is only 3.7.7.

Fix 2
The error message seen in log is:
[ERR][wb_admin_control.py:get_config_options:760]:
 Could not open the file "C:\ProgramData\MySQL\MySQL Server 8.0\my.ini":
 'charmap' codec can't decode byte 0x9d in position 4273: character maps to <undefined>

To fix the problem, patch the same file as indicated:
@@ -315,7 +315,9 @@
     @classmethod
     def get_file_lines(self, path, skip, output_handler):
         try:
-            f = open(path, 'r')
+            # psam fix 30/01/22
+            # f = open(path, 'r')
+            f = open(path, 'r', encoding='utf-8')
 
             skipped = 0
             for line in f:
[2 Feb 2022 10:40] Pat Sam
Another fix to avoid the error when clicking the button "Apply..." in Navigator / INSTANCE / 'Options File'

Patch C:/Program Files/MySQL/MySQL Workbench 8.0/modules/wb_admin_config_file_be.py
@@ -1147,7 +1147,7 @@
 
         tempdir = tempfile.gettempdir()
         self.temp_file_name = os.path.join(tempdir, "mysql_workbench_config.temp")
-        outf = open(self.temp_file_name, "w")
+        outf = open(self.temp_file_name, "w", encoding='utf-8')
         eol = "\n"
 
         for line in file_lines:
@@ -1170,7 +1170,7 @@
 
         temp_file_content = ""
         try:
-            outf = open(self.temp_file_name, "r")
+            outf = open(self.temp_file_name, "r", encoding='utf-8')
             temp_file_content = outf.read()
             outf.close()
         except BaseException as e:
[4 Feb 2022 16:10] Lucas Werquin
This fix worked for me ( Windows 10, french ) :

To fix the problem, patch the following file as indicated:
C:\Program Files\MySQL\MySQL Workbench 8.0\workbench\os_utils.py
@@ -353,7 +353,9 @@
             # Note that self._command contains the internal command so EXEC
             # and self._args is the real OS command to be executed
             # Executes the command, reading the output from the PIPE
-            process = subprocess.Popen(command, stdin = subprocess.PIPE, encoding="utf-8", stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell=True)
+            # psam fix 30/01/22
+            # process = subprocess.Popen(command, stdin = subprocess.PIPE, encoding="utf-8", stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell=True)
+            process = subprocess.Popen(command, stdin = subprocess.PIPE, text=True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell=True)
 
             # Sends all the command output to the listener
             if output_handler:
[31 May 2022 6:52] MySQL Verification Team
Bug #106746 marked as duplicate of this one
[25 Jul 2022 6:43] MySQL Verification Team
Bug #107885 marked as duplicate of this one.
[25 Jul 2022 6:54] GuoLiang Ma
通过更改编码方式解决了,系统是win11
C:\Program Files\MySQL\MySQL Workbench 8.0\workbench\os_utils.py

# process = subprocess.Popen(command, stdin = subprocess.PIPE, encoding="utf-8", stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell=True)

process = subprocess.Popen(command, stdin = subprocess.PIPE, encoding="gbk", stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell=True)
[29 Mar 2023 10:38] MySQL Verification Team
Bug #110539 marked as duplicate of this one.
[5 Jun 2023 6:00] MySQL Verification Team
Bug #111267 marked as duplicate of this one
[5 Jun 2023 7:37] Miklós Csuvár
Hello,

I tried the following fixes according to the following comments:
[16 Apr 2021 8:04] MySQL Verification Team
    I changed the system locale to English.
    The bug persist.
[30 Jan 2022 17:58] Pat Sam
    I carried out Fix 1 and Fix 2 (set both of them to non-UTF-8, while system locale was set to English, and UTF-8 when system locale beta was also checked).
    The bug persist.
[2 Feb 2022 10:40] Pat Sam
    I carried out both of the modifications in accordance with the codepage (if system local beta was checked or not.)
    The bug persist.

I think I carried out a quite thorough test, though I did not perform all the 2^6 tests (system locale language and its beta option, Fix 1 and 2, wb_admin_config_file_be.py modification 1 and 2).

Summary: In spite of the hopes of MySQL team at #111267 ([5 Jun 5:59] MySQL Verification Team), I still feel my issue is somewhat different.

I need more guidance to solve the problem.