unity3D连接mysql数据库:
1.下载安装mysql-connector-net-5.0.6,完成后将C:\Program Files (x86)\MySQL\MySQL Connector Net 5.0.6\Binaries\.NET 2.0下的MySql.Data.dll拷贝到unity工程的assets文件夹下
2.同时将unity安装路径E:\softset\unity4.6.3\Editor\Data\MonoBleedingEdge\lib\mono\2.0下的System.Data.dll拷贝到unity工程的assets文件夹下
3.在连接数据库的脚本中引入命名空间:using MySql.Data.MySqlClient;
可能会出现的问题:
1. Internal compiler error. See the console log for more information. output was:
Unhandled Exception: Mono.CSharp.InternalErrorException: Assets/Sctipts/Ui/Register.cs(8,14): Register ---> Mono.CSharp.InternalErrorException: Assets/Sctipts/Ui/Register.cs(14,39): Register.dbConnection ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
File name: 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
解决方法:项目工程缺少System.Drawing.dll将unity安装路径E:\softset\unity4.6.3\Editor\Data\MonoBleedingEdge\lib\mono\2.0下的System.Drawing.dll拷贝到unity工程的assets文件夹下
2. 运行时可能会出现:MissingMethodException: Method not found: 'System.Threading.Monitor.Enter'.
这是由于连接mysql的dll文件与平台版本不匹配引起的,我的unity版本为unity4.6.3,与mysql-connector-net-5.0.6是兼容的
资源分享:
mysql-connector-net-5.0.6下载:https://yunpan.cn/cY89e4BvYc395 访问密码 23df
mysql-connector-net-6.6.7下载:https://yunpan.cn/cY89XkhzYhgfB 访问密码 4753
unity4.6.3 下载:https://yunpan.cn/cY89bfiEgnWD8 访问密码 a315