Wiki

Set-up MySQL Client Access on Unix-like Systems

Introduction

This guide will show you how to set up MySQL access for NovellMono on UnixLike systems. If you have problems, see the References at the end. You should be able to get this working with that information. Then please update this wiki page.

Assumptions

This guide assumes that:

  • You are on a UnixLike box (Mac, Linux, etc.)
  • You have installed MySQL server
  • You have started MySQL server
  • You have installed Cobra
  • You have downloaded the "MySQL connector for .NET" to a local directory called Packages

Set-up MySQL Client Access

Note that the "sudo" prefix in some commands below is not necessary if you are running as root or have the permissions to the installation directories.

From the command line:

mkdir mysqlcon
cp Packages/mysql-connector-net-6.0.4-noinstall.zip mysqlcon/
cd mysqlcon
unzip mysql-connector-net-6.0.4-noinstall.zip
cat README
mv mysql.data.dll MySql.Data.dll
sudo gacutil -i MySql.Data.dll
    Installed MySql.Data.dll into the gac (/Library/Frameworks/Mono.framework/Versions/2.4/lib/mono/gac)

If you like, you can "rm -rf" the "mysqlcon" directory as the .dll now resides in the GAC. You'll want to keep the original .zip around in case you need to install on another machine or reinstall.

There are some other DLLs in there like mysql.data.cf.dll, mysql.data.entity.dll, mysql.visualstudio.dll and mysql.web.dll. I have not explored them other than to take a quick glance at the types contained therein. Everything I seem to need at this time is in the on DLL, MySql.Data.dll.

The namespaces in MySql.Data.dll are:

You can use .NET Reflector or some other tool to explore the DLL in more detail.

Let's try it out.

$ cd /usr/local/cobra/current/HowTo/
$ cobra -ref:System.Data -ref:MySql.Data 600-AccessMySQL.cobra 
error: cannot find metadata file "MySql.Data.dll"
Compilation failed - 1 error, 0 warnings
Not running due to errors above.

Well that's not very exciting. Let's try the full path:

$ cobra -ref:System.Data \
  -ref:/Library/Frameworks/Mono.framework/Versions/2.4/lib/mono/gac/MySql.Data/6.0.4.0__c5687fc88969c44d/MySql.Data.dll \
  600-AccessMySQL.cobra 
userName=root, host=localhost
userName=root, host=mycomputer.local
userName=, host=mycomputer.local
userName=, host=localhost

At this point, I don't know why the absolute path is required given that the DLL was installed to the GAC (or maybe it worked on your system without the absolute path). But I do know that the fix on Mac OS X is:

$ cd ~/mysqlcon
$ sudo cp MySql.Data.dll /Library/Frameworks/Mono.framework/Libraries/
$ cd /usr/local/cobra/current/HowTo/
$ cobra -ref:System.Data -ref:MySql.Data 600-AccessMySQL.cobra 
userName=root, host=localhost
userName=root, host=mycomputer.local
userName=, host=mycomputer.local
userName=, host=localhost

Cobra's "use" clause will look for a DLL with the matching name, so you can also just issue:

$ cobra 600-AccessMySQL.cobra

Going Further

Look at the source code for 600-AccessMySQL.cobra to see how basic queries are done.

See also: ADO.NET, ActiveRecord

References