可以做推广的门户网站,wordpress 首页更换,工业设计软件有哪些软件,外包网用的unity2021版本#xff0c;MySQL是官方下载的最新版8.0.36.
安装MySQL时#xff0c;过去如果安装过#xff0c;一定要删干净#xff0c;单纯的卸载不行#xff0c;网上有很多教程。
MySQL安装完成后#xff0c;将安装目录的MySql.Data.dll文件放入unity项目的Plugin…用的unity2021版本MySQL是官方下载的最新版8.0.36.
安装MySQL时过去如果安装过一定要删干净单纯的卸载不行网上有很多教程。
MySQL安装完成后将安装目录的MySql.Data.dll文件放入unity项目的Plugins文件夹,Plugins文件夹如果没有在Assets目录下创建一个。
接着打开unity安装目录的C:\Program Files\Unity 2021.1.4f1\Editor\Data\MonoBleedingEdge\lib\mono\unityjit文件夹将里面的
五个文件复制后放入项目的Plugins文件夹。
如果有报错尝试调整下player setting的这两个地方可能根据unity版本和mysql版本的不一样此处选项也不一样我这样设备没有报错了。 如果还有关于MySql.Data.dll文件的报错具体报错代码我忘记了可能是MySql.Data.dll文件的版本问题去网上找一个低版本(8.0以下版本)的MySql.Data.dll文件。
然后是unity连接MySQL的代码 public static MySqlConnection mysql;static string ip /*localhost*/127.0.0.1;static string port 3306;static string database user;static string user root;static string password 123456;void Start(){string connectionString string.Format(server{0};port{1};database{2};user{3};password{4};SslModenone,ip, port, database, user, password);mysql new MySqlConnection(connectionString);Debug.Log(数据库链接成功);}public void Load(){try{mysql.Open();string _username userIF.text;string _password passwordIF.text;MySqlCommand command new MySqlCommand(select * from users where username_username and password_password, mysql);command.Parameters.AddWithValue(_username, _username);command.Parameters.AddWithValue(_password, _password);MySqlDataReader md command.ExecuteReader();if (md.Read()){Debug.Log(登陆成功);GlobalData.userName _username;Debug.Log(GlobalData.userName);SceneManager.LoadScene(Main);}else{xiaoxi.text 账户或密码不正确;}}finally {mysql.Close();}}
如果在执行 mysql.Open();时报了连接器的错误则需要给mysql安装或者更新.net连接器。在mysql Installer中更新。
如果报了关于握手的问题则需要在连接代码中添加SslModenone。
如果报了密码验证问题
MySql.Data.MySqlClient.MySqlException:“Authentication method ‘caching_sha2_password’ not supported by any of the available plugins.”
则需要在C:\ProgramData\MySQL\MySQL Server 8.0文件夹中 给my.ini文件中添加字段 然后打开MySQL,请如下操作 1.1ALTER USER rootlocalhost IDENTIFIED BY password PASSWORD EXPIRE NEVER; #修改加密规则 1.2ALTER USER rootlocalhost IDENTIFIED WITH mysql_native_password BY password; #更新一下用户的密码 1.3FLUSH PRIVILEGES; #刷新权限 1.4再重置下密码alter user rootlocalhost identified by 123456; 最后在服务程序中重启mySQL.
现在已经可以在unity中正常访问mySQL了。