Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
2
Question by bhayes1 · Apr 09, 2017 at 05:36 AM · mysql

MYSQL & Unity, Where to get the libraries to reference?

Hey guys. Theres a lot on MSQL and unity out there in the forums.

But they all have broken links to demo projects and libraries needed. I cant even begin trying the tutorials people offer because I cant reference the libraries in mono develop.

There are asset store items for MySql but even there the links to documentation or demo's etc are broken. No documentation , contact, or website. So I'm hesitant to spend any money when they cant even keep their website references on the asset store up to date.

Ive never tried using Mysql in unity & there seems to be no way to begin.

I see a lot of people using DLL's or unity imports in their tutorials that I cant find anywhere.

Also this is an Android project. Are the DLL's I need even going to work once I deploy the project on to an android device?

Any advice on where to begin?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by remekgc · Mar 03, 2020 at 08:57 PM

Hello there, I have faced the same problem yesterday and I've found a satisfying solution that works both on PC and Android.

  • Step 1: Download .DLL file from here matching your Visual studio project target .NET version (for me 3.5, version 6.9.8.0 worked just fine). If you download a wrong version you will get an error in Unity editor. links to download the file: https://www.dllme.com/dll/files/mysql_data_dll.html or this one: https://downloads.mysql.com/archives/c-net/

  • Step 2: Unpack the .DLL file and include it in the project (put it anywhere inside of the Assets folder).

  • Step 3: Program your connection to the database ;) here is a short example:

       using System;
         using System.Data;
         
         using MySql.Data;
         using MySql.Data.MySqlClient;
         
         public class Tutorial4
         {
             public static void Main()
             {
                 string connStr = "server=localhost;user=root;database=world;port=3306;password=******";
                 MySqlConnection conn = new MySqlConnection(connStr);
                 try
                 {
                     Console.WriteLine("Connecting to MySQL...");
                     conn.Open();
         
                     string sql = "SELECT COUNT(*) FROM Country";
                     MySqlCommand cmd = new MySqlCommand(sql, conn);
                     object result = cmd.ExecuteScalar();
                     if (result != null)
                     {
                         int r = Convert.ToInt32(result);
                         Console.WriteLine("Number of countries in the world database is: " + r);
                     }
         
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.ToString());
                 }
         
                 conn.Close();
                 Console.WriteLine("Done.");
             }
         }
     
     
     
    
    
    
    
    
    
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Da_Elf · Jun 27, 2020 at 06:24 PM

Im using unity 2019 and i can get the connection to open. And using the ExecuteScalar() with a COUNT() seems to work just fine. However when i try to do "SELECT username FROM users" and using other OLD tutorials I used the code below I get a System.TimeoutExeption: error

 // TEST 2
 Debug.Log("Test 2");
 string sql2 = "SELECT username FROM users";
 cmd = new MySqlCommand(sql2, con);
 rdr = cmd.ExecuteReader();
 while (rdr.Read())
 {
     Debug.Log(rdr[0]);
 }
 rdr.Close();

So i tried something else. "SELECT * FROM users" And this time i get a different error. . .

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x0001e] in :0 > at MySql.Data.MySqlClient.CharSetMap.GetCharacterSet > (MySql.Data.Common.DBVersion version, > System.String CharSetName) [0x00000] > in > :0 > at MySql.Data.MySqlClient.MySqlField.SetFieldEncoding > () [0x0004b] in > :0 > at MySql.Data.MySqlClient.MySqlField.set_CharacterSetIndex > (System.Int32 value) [0x00007] in > :0 > at MySql.Data.MySqlClient.NativeDriver.GetColumnData > (MySql.Data.MySqlClient.MySqlField > field) [0x000ad] in > :0 > at MySql.Data.MySqlClient.NativeDriver.GetColumnsData > (MySql.Data.MySqlClient.MySqlField[] > columns) [0x00004] in > :0 > at MySql.Data.MySqlClient.Driver.GetColumns > (System.Int32 count) [0x0001c] in > :0 > at MySql.Data.MySqlClient.ResultSet.LoadColumns > (System.Int32 numCols) [0x00000] in > :0 > at MySql.Data.MySqlClient.ResultSet..ctor > (MySql.Data.MySqlClient.Driver d, > System.Int32 statementId, System.Int32 > numCols) [0x00029] in > :0 > at MySql.Data.MySqlClient.Driver.NextResult > (System.Int32 statementId) [0x00035] > in > :0 > at MySql.Data.MySqlClient.MySqlDataReader.NextResult > () [0x00053] in > :0 > at MySql.Data.MySqlClient.MySqlDataReader.Close > () [0x00020] in > :0 > at MySql.Data.MySqlClient.MySqlCommand.ResetReader > () [0x00020] in > :0 > at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader > (System.Data.CommandBehavior behavior) > [0x002d1] in > :0 > at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader > () [0x00000] in > :0 > at (wrapper remoting-invoke-with-check) > MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() > at DatabaseHandler.Awake () [0x00176] in C:\Users\St Francis > 01\Desktop\AGD\MySQL\Link To > MySQL\Assets\Scripts\DatabaseHandler.cs:68 > > UnityEngine.Debug:Log(Object) > DatabaseHandler:Awake() (at Assets/Scripts/DatabaseHandler.cs:77)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

98 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there any tutorials on using MySQL and Unity? 0 Answers

Windows Standalone and MySQL: NotSupportedException 0 Answers

warning CS0649: Field `name.username' is never assigned to, and will always have its default value `null' 3 Answers

OdbcDatReader problems 0 Answers

Why is MySQL search query not returning each row in 1 index of an array? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges