大望路网站建设,招商网站建设简介,网站开发加33865401,跟我一起学做网站链接MySql5.7
前言#xff1a; 为什么不选择最新的MySQL8.0或者MySQL8.2呢#xff0c;实际发现#xff0c;如果使用这两个版本#xff0c;虽然能够用同样的方法找到合适的dll#xff0c;但是在编写代码的过程中往往会卡死#xff0c;非常的影响效率#xff0c;因此放弃…链接MySql5.7
前言 为什么不选择最新的MySQL8.0或者MySQL8.2呢实际发现如果使用这两个版本虽然能够用同样的方法找到合适的dll但是在编写代码的过程中往往会卡死非常的影响效率因此放弃使用这两个版本的MySQL。
1.准备dll
一、找到l18N相关的dll
这里给出一个参考地址
D:\Unity\2020.3.48f1c1\Editor\Data\MonoBleedingEdge\lib\mono\unityjit在里面找到如下图的四个dll 二、下载数据库链接dll
https://downloads.mysql.com/archives/c-net/在这里搜索历史版本(Archive),找到5.2.3这一版本下载安装即可。 安装完成后会得到一个压缩包把里面bin目录下的MySql.Data.dll拷贝出来
2.Unity使用dll
注意要打开数据库
将插件拖入Plugin文件夹中。 接下来编写脚本
using MySql.Data.MySqlClient;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class MysqlConnect : MonoBehaviour
{public void InquireMysql(){string sqlSer server 127.0.0.1;port 3306;database icms;user root;password 123456;charsetutf8;MySqlConnection conn new MySqlConnection(sqlSer);try{conn.Open();Debug.Log(-------链接成功-------);string sqlQuary select * from account;MySqlCommand comd new MySqlCommand(sqlQuary, conn);MySqlDataReader reader comd.ExecuteReader();while (reader.Read()){//通过reader获得数据库信息Debug.Log(reader.GetString(Account));Debug.Log(reader.GetString(Password));}}catch{Debug.Log(error);}}
}将这个脚本随便挂一个物体上button触发。
By-Round Moon