Connection between Unity and database (MySQL)

 Create a folder named Plugins in Accest, and put MySql.Data, System.Data, and System.Drawing into the folder.

 Open MySql to create database and table

 Create c# code in unity

using MySql.Data.MySqlClient;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Test : MonoBehaviour
{
    public static MySqlConnection conn;//声明数据库
    public static string ConStr= "Database=myscoresdb;Data Source=localhost;User Id=root;Password=root;port=3306";//数据库名,表名,用户名,密码,端口号

    void Start()
    {
        conn = new MySqlConnection(ConStr);//连接数据库
        conn.Open();//打开数据库
        Debug.Log("成功连接数据库");
    }
   
}

 Mount the code in the camera and click to run

Guess you like

Origin blog.csdn.net/qq_57388481/article/details/127689038