# MySQL integration in UE4 with C++

**URL:** <https://forums.unrealengine.com/t/mysql-integration-in-ue4-with-c/20268>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [February 4, 2015, 1:32am UTC](https://forums.unrealengine.com/t/mysql-integration-in-ue4-with-c/20268 "2015-02-04T01:32:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NouRuem](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NouRuem](https://forums.unrealengine.com/u/NouRuem)\
**Post date:** [February 4, 2015, 1:32am UTC](https://forums.unrealengine.com/t/mysql-integration-in-ue4-with-c/20268/1 "2015-02-04T01:32:23Z")

</div>

Hi everybody.

I need a help with MySQL in the UE4.  
I managed to make a program in C ++ to read the database in an online server.  
It works on the project in Visual Studio 2013 C ++. Follow the design codes:

```auto

String^ PATH = L"datasource=mysql1.alwaysdata.com; username=dbuser; password=p@ass8585";
MySqlConnection^ conDataBase = gcnew MySqlConnection(PATH);
MySqlCommand^ cmdDataBase = gcnew MySqlCommand("SELECT * FROM nouruem_otz.usuarios"), conDataBase);
MySqlDataReader^ myReader;
try
{
	conDataBase->Open();
	myReader = cmdDataBase->ExecuteReader();
	conDataBase->Close();

	MessageBox::Show("User and password successfully inserted!");
	}
		catch (Exception^ ex)
	{
	
	MessageBox::Show(ex->Message);
}

```

NOTE: Not a lot of attention to the SQL command, I put this only as an example.

To operate this project in C ++, I added an external reference named MySQL.Data.dll.

I’m using namespace below.

```auto

using namespace MySql::Data::MySqlClient;

```

The goal is that the database be “stored” in a web server.

Thank you in advance any help.

---

<div class="post-metadata">

**Author:** ![Young\_Wolf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Young\_Wolf](https://forums.unrealengine.com/u/Young_Wolf)\
**Post date:** [February 5, 2015, 10:33am UTC](https://forums.unrealengine.com/t/mysql-integration-in-ue4-with-c/20268/2 "2015-02-05T10:33:27Z")

</div>

Hi, I see that you are using C#'s library to connect ot MySQL. I managed to get working C++ library. When I get hope I will upload the .dll file that is used for UE4. Cuz there are two versions, one for VS2013 and one for UE4.

---

<div class="post-metadata">

**Author:** ![NouRuem](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NouRuem](https://forums.unrealengine.com/u/NouRuem)\
**Post date:** [February 5, 2015, 7:01pm UTC](https://forums.unrealengine.com/t/mysql-integration-in-ue4-with-c/20268/3 "2015-02-05T19:01:43Z")

</div>

Did not quite understand.

MySQL itself already be releasing the DLL to work with UE4 or you could make that MySQL connection and UE4 on their own?

Anyway, I appreciate the response.

---

<div class="post-metadata">

**Author:** ![Young\_Wolf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Young\_Wolf](https://forums.unrealengine.com/u/Young_Wolf)\
**Post date:** [February 7, 2015, 12:25pm UTC](https://forums.unrealengine.com/t/mysql-integration-in-ue4-with-c/20268/4 "2015-02-07T12:25:47Z")

</div>

When I tried connecting UE4 to MySQL first thing was to look for a UE4 class to connect to MySQL but all I found was Http class to sent post requests to web server. Then I started a thread about which is better:  
Sending information to web server, and from there save it in database, or directly send information from the game to the database. Most of the people there said it’s better to send data from game directly to database. And a guy sent me this library:[Download](https://mega.co.nz/#!M8NhBTzY!ArRKS2vBYLVyT0a4gE5xq3Biad1S7u75zQBXo141i2k)

I believe the MD was for Visual Studio and MT was for UE4.

I only tried using MD and managed to connect from console to database. I believe that connecting to MySQL via UE4 would require these steps:

1. Import the .dll file to UE4 and include the headers [wiki.unrealengine.com/Linking\_Dlls](https://wiki.unrealengine.com/Linking_Dlls)
2. Write a class with function to pull data from database, put data into database and delete data from database
3. Create instances of this class wherever you need it and access those functions in your game.

For example you wrote a class DatabaseConnection which has functions dbconn-\>query(FString query) which will execute a query on the database and stuff and save the result in a variable. Then use that variable to output the result in your game.

Sorry for not replying for so long 🙂 Hope that helps a bit. If you have problems with that feel free to find me on skype (uadmin1) and we can discuss this even further!
