Bug #98791 Fail to install MySQL on Windows due to a .NET Connector bug
Submitted: 1 Mar 2020 15:36 Modified: 21 Apr 2020 12:27
Reporter: Kang Qiao Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL for Windows: Installer Severity:S3 (Non-critical)
Version:8.0.19 OS:Windows (10)
Assigned to: CPU Architecture:x86 (laptop)

[1 Mar 2020 15:36] Kang Qiao
Description:
I have been struggling for a whole day, trying to install the latest version of MySQL Community Edition (8.0.19 GA) on Windows 10 on my laptop but keep getting the same error on the configuration stage:

  Retry 10: Attempting to connect to Mysql@localhost:3306 with user root with no password...
  MySQL error 1042: Unable to connect to any of the specified MySQL hosts.
  Failed to connect to MySQL Server 8.0.19 after 10 attempts.
  Ended configuration step: Starting the server

I locate the installation log and get a few more details:

  mysql-installer Error: 50 : Sequence contains more than one matching element

This turns out to be a .NET Framework LINQ exception. You will get it if you try to invoke .Single() or .SingleOrDefault() on a collection with more than one element.

I google this message and find a previous bug report with the same error message: https://bugs.mysql.com/bug.php?id=97448, which is caused by MySQL .NET Connector. So I guess I'm encountering a similar one.

I decompile the Connector DLL shipped with the installer (C:\Program Files (x86)\MySQL\MySQL Installer for Windows\MySql.Data.dll) using dnSpy(https://github.com/0xd4d/dnSpy). The bug seems to be here:

  // namespace: MySql.Data.Common
  // class: StreamCreator
  // method: GetTcpStream(settings)
  Task<IPAddress[]> hostAddressesAsync = Dns.GetHostAddressesAsync(settings.Server);
  hostAddressesAsync.Wait();
  if (hostAddressesAsync.Result == null || hostAddressesAsync.Result.Length == 0)
  {
    throw new ArgumentException(Resources.InvalidHostNameOrAddress);
  }
  IPAddress ipaddress = hostAddressesAsync.Result.SingleOrDefault((IPAddress c) => c.AddressFamily == AddressFamily.InterNetwork);
                                                  ---------------!!!
  if (ipaddress == null)
  {
    ipaddress = hostAddressesAsync.Result[0];
  }

To confirm it, I execute this command on a PowerShell prompt:

  [System.Net.Dns]::GetHostAddresses("localhost") | Where-Object {$_.AddressFamily -eq 'InterNetwork'}

And get two addresses, both having an IP of 127.0.0.1:

  Address            : 16777343
  AddressFamily      : InterNetwork
  ScopeId            :
  IsIPv6Multicast    : False
  IsIPv6LinkLocal    : False
  IsIPv6SiteLocal    : False
  IsIPv6Teredo       : False
  IsIPv4MappedToIPv6 : False
  IPAddressToString  : 127.0.0.1
  
  Address            : 16777343
  AddressFamily      : InterNetwork
  ScopeId            :
  IsIPv6Multicast    : False
  IsIPv6LinkLocal    : False
  IsIPv6SiteLocal    : False
  IsIPv6Teredo       : False
  IsIPv4MappedToIPv6 : False
  IPAddressToString  : 127.0.0.1

I don't figure out why. I try to disable IPv6 and disable all my network adapters but I still can get two.

I hack the Connector DLL, replacing '.SingleOrDefault()' with '.FirstOrDefault()'. Then I can go through the configuration successfully.

With this bug, you will get an incorrect password error at 'Accounts and Roles' when you attempt to reconfigure MySQL Server after a failed installation.

Related:
  - Installer for 8.0.11 fails to connect to server
    https://forums.mysql.com/read.php?169,667002,667002
  - Unable to connect to any of the specified MySQL hosts
    https://forums.mysql.com/read.php?169,675957,675957
  - MySQL.Data v8.0.18 fails if more than one IP is found in DNS for a named host
    https://forums.mysql.com/read.php?38,678859,678859
  - MySQL Bugs: #97448: MySQL.Data v8.0.18 fails if more than one IP is found in DNS for a named host
    https://bugs.mysql.com/bug.php?id=97448

How to repeat:
Find a Windows computer where 'localhost' resolves to two 127.0.0.1 addresses. Use the following PowerShell command to confirm it. Then run the MySQL installer.

[System.Net.Dns]::GetHostAddresses("localhost") | Where-Object {$_.AddressFamily -eq 'InterNetwork'}

Suggested fix:
Fix the bug here: https://bugs.mysql.com/bug.php?id=97448

And replace the repaired .NET Connector into the installer.
[21 Apr 2020 12:27] MySQL Verification Team
Hello Kang Qiao,

Thank you for the bug report and feedback.
Please be informed that bug #97448 is fixed and as per the closure note  - it is fixed as of the upcoming MySQL Connector/NET 8.0.20 release . Please see bug #97448. Thank you!

Regards,
Ashwini Patil