【Unity】连接MySQL实现增、删、改、查

1.需要先安装MySQL,如果已经安装则忽略

安装教程: MySQL安装教程

2.下载mysql-connector-net库

官方下载地址:https://downloads.mysql.com/archives/c-net/
提示:选择和自己MySQL相匹配的版本,不然会跟unity版本匹配不上。
我MySQL是5.6.39 下载的mysql-connector-net库是5.2.7
在这里插入图片描述

3.解压后,找到mysql.data.dll,放入Unity工程里

请添加图片描述

4.在Unity的安装目录下,把这几个dll放入Unity资源的Plugins文件夹中,防止打包出来连不上数据库。

我的路径为:C:\Program Files\Unity\Hub\Editor\2021.3.33f1c1\Editor\Data\MonoBleedingEdge\lib\mono\unityjit-win32
请添加图片描述

5.执行脚本

using MySql.Data.MySqlClient;
using System;
using System.Data;
using UnityEngine;
 
public class Test : MonoBehaviour
{
   
    public MySqlConnection mysql;
    static string host = "localhost";
    static string port = "3306";
    static string username = "root";
    static string pwd = "123456";
    static string database 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值