4.2 KiB
| author | date | title |
|---|---|---|
| Brazil | March 2026 | SQL |
TinyMUX 2.14 supports both asynchronous and synchronous SQL. The
synchronous/in-line support is similar to that of PennMUSH and TinyMUSH,
namely the sql() function. The asynchronous support is unique to TinyMUX
at this time and is the recommended method for SQL access.
Asynchronous SQL
-
To enable this functionality, you will need to pass
--enable-stubslaveto the configure script. If your MySQL is not in the default location (namely,/usr/include/mysqland/usr/lib/mysql), then you will need to tell configure where to find the headers and libraries with the--with-mysql-includeand--with-mysql-libsoptions. For instance:./configure --enable-stubslave \ --with-mysql-include=/usr/local/mysql/include \ --with-mysql-libs=/usr/local/mysql/lib -
Once the game has been compiled you will need to add six configuration options to the
.conffile. You can check the wizhelp file for more information regarding the options. The six are listed below:module sqlproxy module sqlslave local sql_database <name of database> sql_server <localhost or address> sql_user <MySQL username> sql_password <MySQL password> -
Start the game and check the log file. You should see entries like the following:
MUX NET/STUB : Stub slave started on fd 3 MUX INI/LOAD : Registered netmux modules. MUX INI/LOAD : Opened interface for StubSlave management.To perform MySQL queries you will use the
@querycommand in conjunction with thersrelease(),rserror(),rsprev(),rsrecnext(),rsrows(),rsrec(),rsnext()andrsrecprev()functions. Here's an example:&FOO.TR me= @if rserror()= { @pemit %#=Rows: [rsrows()]; @if rsrows()= { @trig me/bar.tr } }, { @pemit %#=Error: [rserror()] } &BAR.TR me= @pemit %#=rsrec(|); @if rsnext()= { @trig me/bar.tr } @query/sql me/foo.tr=/show databases; -
This method will allow SQL queries to occur without blocking the main game process. If the SQL is on another machine, slow or even has been disabled or crashed then the game will not hang while waiting on the result to be returned.
In-Line/Synchronous SQL
-
To enable this functionality, you will need to pass
--enable-inlinesqlto the configure script. If your MySQL is not in the default location (namely,/usr/include/mysqland/usr/lib/mysql), then you will need to tell configure where to find the headers and libraries with the--with-mysql-includeand--with-mysql-libsoptions. For instance:./configure --enable-inlinesql \ --with-mysql-include=/usr/local/mysql/include \ --with-mysql-libs=/usr/local/mysql/lib -
Once the game has been compiled you will need to add four configuration options to the
.conffile. The four are listed below:sql_database <name of database> sql_server <localhost or address> sql_user <MySQL username> sql_password <MySQL password> -
Start the game and check the log file. You should see entries like the following:
SQL/CONN : Connecting: <database>@<address> as <user> SQL/CONN : Connected to MySQLYou can use the
sql()function to perform MySQL queries. Seehelp sql(). -
The SQL code enabled with
--enable-inlinesqlruns synchronous with the TinyMUX process. That means that in the game when you use thesql()function to make a query, the whole game waits on the query to finish. If you're on a server which is not overloaded and has good, free resources and where the MySQL server is running on the same machine then this should not be a problem as long as the MySQL server remains running. If the server is overloaded and therefore slow or if the MySQL server is on a different machine, then there can be a delay in getting the results. That delay will mean the whole game hangs while waiting.When using the in-line SQL functionality bear this potential problem in mind. You should test your game with the SQL functionality first before using it in a live environment.