首先找到这两个东西
在Unity中的Assets文件夹新建一个名叫Plugins的子文件夹
将上面的两个插件加载进这个文件夹
先引入using MySql.Data.MySqlClient;这个空间
public class mytest : MonoBehaviour { void Start () { Ping(); } void Ping () { //表示服务器和所要操作的数据库,用户名和密码 string a = "server=localhost;database=teacher;userid=root;password=root;"; MySqlConnection con = new MySqlConnection(a); //打开连接 con.Open(); //增加 //string sql = "insert into xinxi(name,sex,age,salary) values('邱龙华','男',21,90000)"; //删除 //string sql = "delete from xinxi where id=4"; //修改 //string sql = "update xinxi set name='彭锦涛' where id=3"; string sql = "select * from xinxi"; MySqlCommand com = new MySqlCommand(sql,con); // if (com.ExecuteNonQuery()>0) // { //print("OK"); // } // else // { //print("NO"); // } //查询 MySqlDataReader read = com.ExecuteReader(); //要查询的数据 while (read.Read()) { int id = read.GetInt32("id"); string name = read.GetString("name"); string sex = read.GetString("sex"); int age = read.GetInt32("age"); float salary = read.GetFloat("salary"); //打印读取的数据 print(id+"\t"+name+"\t"+sex+"\t"+age+"\t"+salary); } //关闭(释放)资源 read.Close(); con.Close(); } }