Installing MySql Connector for Mono

DOTNET and Mono by default only support database connections to the Microsoft SQL Server through System.Data.SqlClient module. To make a connection to the MySQL server you need a connector module from MySQL.

Proceed with the following steps to obtain and install the MySQL .NET Connector:

1. Downloading MySQL .NET Connector

Either from MySQL (requires registration):

http://www.mysql.com/downloads/mirror.php?id=399565

or directly from one of the mirros:

ftp://ftp.gwdg.de/pub/misc/mysql/Downloads/Connector-Net/mysql-connector-net-6.3.6-noinstall.zip

3. Unzip the content into a directory

~> md connector
~> cd connector
~/connector> unzip ../mysql-connector-net-6.3.6-noinstall.zip
~/connector> ls
CHANGES  COPYING  MySql.Data.chm  README  Release Notes.txt  v2  v4

4. Change names of assemblies to proper names

~/connector> cd v2
~/connector/v2/ mv mysql.data.cf.dll MySql.Data.Cf.dll
~/connector/v2> mv mysql.data.dll MySql.Data.dll
~/connector/v2> mv mysql.data.entity.dll MySql.Data.Entity.dll
~/connector/v2> mv mysql.visualstudio.dll MySql.VisualStudio.dll
~/connector/v2> mv mysql.web.dll MySql.Web.dll
~/connector/v2> cd ../v4
~/connector/v4> mv mysql.data.dll MySql.Data.dll
~/connector/v4> mv mysql.data.entity.dll MySql.Data.Entity.dll
~/connector/v4> mv mysql.visualstudio.dll MySql.VisualStudio.dll
~/connector/v4> mv mysql.web.dll MySql.Web.dll

5. Copy assemblies into library directory of your mono installation

~/connector/v4> su
/home/user/connector/v4 # cp MySql.* /usr/lib/mono/4.0/.
/home/user/connector/v4 # cd ../v2
/home/user/connector/v2 # cp MySql.* /usr/lib/mono/2.0/.

6. Register the installed assemblies in the global assembly cache

~ # cd /usr/lib/mono/4.0
/usr/lib/mono/4.0 # gacutil -i MySql.Data.dll
Installed MySql.Data.dll into the gac (/usr/lib/mono/gac)
/usr/lib/mono/4.0 # gacutil -i MySql.Data.Entity.dll
Installed MySql.Data.Entity.dll into the gac (/usr/lib/mono/gac)
/usr/lib/mono/4.0 # gacutil -i MySql.VisualStudio.dll
Installed MySql.VisualStudio.dll into the gac (/usr/lib/mono/gac)
/usr/lib/mono/4.0 # gacutil -i MySql.Web.dll
Installed MySql.Web.dll into the gac (/usr/lib/mono/gac)
/usr/lib/mono/4.0 # cd ../2.0
/usr/lib/mono/2.0 # gacutil -i MySql.Data.Cf.dll
Installed MySql.Data.Cf.dll into the gac (/usr/lib/mono/gac)
/usr/lib/mono/2.0 # gacutil -i MySql.Data.dll
Installed MySql.Data.dll into the gac (/usr/lib/mono/gac)
/usr/lib/mono/2.0 # gacutil -i MySql.Data.Entity.dll
Installed MySql.Data.Entity.dll into the gac (/usr/lib/mono/gac)
/usr/lib/mono/2.0 # gacutil -i MySql.VisualStudio.dll
Installed MySql.VisualStudio.dll into the gac (/usr/lib/mono/gac)
/usr/lib/mono/2.0 # gacutil -i MySql.Web.dll
Installed MySql.Web.dll into the gac (/usr/lib/mono/gac)

Note: For steps 4 (renaming) and 5 (copying), I don’t really understand why these steps are necessary, but on my OpenSuSE 11.3 machine it did only work out that way. Any suggestions to improve this procedure are welcome.

Further reading:

Advertisements
This entry was posted in Database, Installation. Bookmark the permalink.

5 Responses to Installing MySql Connector for Mono

  1. revani says:

    I don’t really understand why these steps are necessary, but on my OpenSuSE 11.3 machine it did only work out that way.

    Linux is case sensitive.

    • 2sharp4u says:

      Correct, however, I think it is fair to expect that .NET with an origin from a non-case-sensitive environment would not get picky on this in a case-sensitive host.

  2. Mat says:

    The assembly name within the dll is stated as MySql.Data, and you reference a library by that name, mono is looking for MySql.Data.dll and not for mysql.data.dll.

    • 2sharp4u says:

      Hi Mat, that point is clear, the tutorial above is addressing exactly this point, but why is Mono unable to handle assembly names in a way compatible with files distributed by Microsoft.

      • Mat says:

        The problem is not caused by the difference between mono and .NET but between Linux and Windows. The assembly names within the assembly are case sensitive, so the runtime is looking for MySq.Data.dll. Linux has case sensitive filenames, so there the dll has to have the correct name. Windows files are not case-sensitive, so looking for MySql.Data.dll there also finds mysql.data.dll.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s