I am developing with Unity targeting Android. How can I directly connect to MySQL?

I am aware that it is not recommended, but I have to do it this way.

Is there a method to directly connect to MySQL when developing with Unity targeting Android? I installed the MySQL connector using Mysql.Data.dll and NuGet, and in the Unity editor, it connects to MySQL and successfully retrieves data. However, when I build it for Android, I get the following error:

Error Unity Error opening MySQL connection: System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlConfiguration' threw an exception. ---> System.NotSupportedException: System.Configuration.ConfigurationManager::GetSection

Is there any solution for this? Or is it impossible?

Please only use the 2D tag when you’re asking about 2D because this puts your question in the 2D product area.

I’ll remove that tag for you.

Thanks.

Out of interest why direct connection? Why not through a web api? (this makes it easy to use for all)

My boss didn’t want it to be done that way. But now it’s been resolved.

while I understand its out of your control, i hope he realises the issues that can occur by not protecting the db with that layer… such as now your db username and password is out in the world, and all tables that can be written to, are now open for them to mess with… but hey

I solved it using web api.