Skip to content

How it connects

Xyranaut edited this page Jun 1, 2026 · 1 revision

How an open.mp server talks to a database

Let's build up the picture one step at a time.

The problem

Your server and your database are two separate programs. They might even be on two different machines. They need a way to talk:

[ open.mp server ] -------- ??? -------- [ MySQL server ]
   (your gamemode)                          (your data)

What goes in the middle? Something has to:

  1. open a network connection to MySQL,
  2. speak MySQL's wire protocol,
  3. keep it secure (you don't want passwords sent in plain text),
  4. not freeze your game while waiting for the database.

That "something" is omp-MySQL.

With omp-MySQL in the middle

[ open.mp server ] -- [ omp-MySQL component ] == TLS ==> [ MySQL server ]
   your .pwn calls          (the translator)              5.7 / 8.x / 9.x
   mysql_execute(...)     speaks MySQL + TLS,
                          runs it off the main thread
  • Your Pawn code calls mysql_* functions.
  • omp-MySQL turns them into real SQL, sends them over an encrypted (TLS) link.
  • The ==> is always encrypted — omp-MySQL refuses to connect without TLS.

What happens on a single query (step by step)

   YOUR GAMEMODE (main thread)              WORKER THREAD            MYSQL
   ---------------------------              -------------            -----
1. mysql_execute(db,
     "SELECT money ...",  ---- hands the job to --->  (queue)
     "OnMoneyLoaded")
                                              2. sends SQL over TLS ----> 
                                                                    3. runs query
                                              4. reads the rows  <--------
   ... game keeps running ...                   (no lag on your server!)
5. next server tick:  <--- result is ready ---
   OnMoneyLoaded() is
   called with the rows

The key idea: step 1 does not wait. Your server keeps ticking (players keep moving, no freeze) while the worker thread does the slow network/database work. When the answer comes back, omp-MySQL calls your callback (OnMoneyLoaded) on the next tick. This is called an asynchronous (async) query.

Why async matters

If the query were synchronous (blocking), your whole server would freeze every time the database was slow — every player would lag. Async means one slow query never stops the game. omp-MySQL gives each connection its own worker thread, so queries run in the background.

Where TLS fits

[ omp-MySQL ] ===== encrypted tunnel (TLS 1.3 / 1.2) ===== [ MySQL ]
                  nobody on the network can read the
                  passwords or data going through

TLS is the same technology that puts the padlock in your web browser. omp-MySQL always uses it and refuses to connect if the server can't do TLS — so your players' hashed passwords and data are never sent in the clear.

The full picture

                         your server machine
   +-------------------------------------------------+
   |  [ omp-server ]                                 |
   |       |  loads                                  |
   |  [ components/omp-mysql.dll | .so ]             |
   |       |   (+ bundled OpenSSL on Windows)        |
   |       |  async, TLS                             |
   +-------|-----------------------------------------+
           |  encrypted MySQL protocol
           v
   +-------------------------------+
   |  [ MySQL server 5.7 / 8 / 9 ] |   (same box, or anywhere on the network)
   |   accounts, vehicles, ...     |
   +-------------------------------+

Now you know what's happening under the hood. Next: Why omp-MySQL? → or jump to Getting started →.

Clone this wiki locally