How do I import MySql Connector into Unity Project?

  • I’ve tried placing the basic dll’s into unity’s assets folder - Result: “blah blah will cause Unity to Crash Error.”
  • I’ve tried Manually adding references - Result: Unity refreshes its references anytime the editor refreshes, so worthless.
  • I’ve tried Installing using NuGet - Result: Closest to success as it handles all the dependencies and whatnot but I get: Assets/Scripts/Developing/TalkToDB.cs(3,7): error CS0246: The type or namespace name `MySql’ could not be found. Are you missing an assembly reference?

Is it some kind of a combination of “Use NuGet then copy the dll into the Assets?” or something redundant like that? cause that’s about the best guess I’ve got.

Also, I’ve tried a couple older versions of the NuGet package to no avail.
As well, MySql.Data is listed under the References of “Assembly-CSharp”
And my Unity is set to 4.X framework Using Unity’s latest 2018.2.5f1 (64bit)
(I really hope that I don’t have to ditch 4.x for this to work… I’ll miss initializing values to properties…)

Fortunately I came across this:

How to get MySql Connector/Net Working with Unity 2017

And Regarding Security concerns. My Key is none of my sessions should ever be persistent from .NET - There will be advanced PHP scripts for altering of data and anything regarding elevated permissions.

Reference: Why you shouldn’t connect your mobile application to a database

Beyond this,

Exceptions to the rule.

"Some database vendors may have provided drivers to connect to remote databases, but as yet I’m not aware of any.

Other exceptions include ODBC connectivity. For example, I’ve heard of developers being able to (or at least trying to) connect to MySQL databases using JDBC when developing applications in Java. This is not actually quite the same as connecting directly using a binary driver, however, it comes close…"

This is exactly what I will be doing, using the MySql Connector to talk to MySql drivers (which I’m too tired at the moment to recall the name of(maybe it’s based on ODBC? I can’t remember. Thus Google. Lol))

So all in all, using the link provided at the top, Unity 2018 can be compatible with the latest (as of this post) MySql Connector(s).

Any Assets folder must contain: System.Data.dll & MySql.Data.dll (that’s it)

No NuGet required.

However the error message: “Loading script assembly ‘Assets/Plugins/MySql/System.Data.dll’ failed!”
And as of yet, it is apparently not able to reference connectionString from an app.config like your normal C# outside of Unity would be able to.
This being said, I’m working on finding either Unity’s implementation of the app.config, or an equivalent alternative.


Aside from a couple annoying dll loading errors in Unity that don’t influence anything - other than annoying me and wasting a couple bytes of RAM for a second (lol, y’kno.);
All works well and I remember the reason I am not concerned about connecting my application directly to my Database is because the ONLY permissions the users will have is the Execute permission so all procedures will be stored on the server (via Stored Procedures) and thus protecting the database against any potential attacks even if cough coughwhencough ahem, a user decides to “de-compile” (is that even a word…? heh) my application.

Final Update:

As I posted here;

It took me a week to finally figure it out…

You need to use:

I18N.*.dll (Optional, they are region specific)

from C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0

NOT the BleedingEdge path. Then it will work without errors [And in Builds]…
confirmed in the latest Unity 2018.2.6f1

I had manually added a System dll into assets folder but it did not work well.

The thing that worked for me was following this Unity Forum thread and using a csc.rsp as Unity Suggests. You can see my answer there.