So, you’re a Linux guy who wants to make cool stuff with the Mono version of the .Net framework and MySQL? Cool story bro. Sadly, there’s no ‘out of the box’ support for MySQL with Mono. That said, it’s reasonably easy to get it working. This blog post will run you through installing the MySQL DLLs so you can start hacking away.
- A brain.
- 20 minutes
- A MySQL Server.
Got those? Awesome.
So, first off open up a terminal and download MonoDevelop. This will also download any and all dependencies, including Mono itself. In Ubuntu, it’s sudo apt-get install monodevelop. Depending on what distro you are using, you may be using a different package manager and you’ll use a somewhat different command.
Now go here and download the latest version of the MySQL .Net connector. Make sure you select the Mono version and not the Microsoft Windows one. Once you’ve got that, you’ll probably want to unzip it. Navigate to the directory where you downloaded the zip file and run unzip <name of file>. You’ll now have two folders called “V2” and “V4”. These contain all the libraries you’re going to have to put into your GAC (Global Assembly Cache).
Now, unfortunately you’re going to have to rename each library. Seriously. Whoever uploaded them didn’t exactly realize that this sort of thing is case sensitive. So, go ahead and rename them to the correct naming convention.
mv mysql.data.cf.dll MySql.Data.Cf.dll
As you can see, you’re changing “mysql” to “MySQL” with every other part of the filename that isn’t “.dll” having the first character uppercase. Makes sense? Good.
Right, now copy everything from “V2” into /usr/lib/mono/2.0 and everything from “V4” into /usr/lib/mono/4.0. Done? Cool. You’re almost finished. Now you get to put it into your Global Assembly Cache. This is handled by a rather nice utility called gacutil which should have been installed when you downloaded MonoDevelop.
Syntax is fairly simple here. It’s just gacutil -i <filename>. Do that for each DLL, and you’re sorted. Seriously, there’s nothing more to do now. Promise. Now, reward yourself by making something cool with MySQL and C#.