Convert mSQL C Source Safely with msql2mysql
msql2mysql rewrites the C source file you give it in place, with no dry run and no output-file option, so the backup step below is not optional. This gets you a converted copy of an mSQL C program, a preserved original, and a quick way to review exactly what changed.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about ten minutes for a small file, plus whatever time you need to review and compile the result. You need a shell, a C source file using the mSQL API, and the mariadb-client package. The examples use the installed MariaDB 10.11.14 client utilities on Ubuntu 24.04; check your own package version before relying on exact details.
1. Check the installed command
An ordinary read-only check, no sudo needed:
$ command -v msql2mysql
/usr/bin/msql2mysql
$ dpkg-query -W -f='${Package} ${Version}\n' mariadb-client
mariadb-client 1:10.11.14-0ubuntu0.24.04.1
The local manpage shows the syntax as msql2mysql C-source-file .... It documents file operands, not a dry-run or output-file option. Treat any invocation as a change to every named source file.
Checkpoint
You have confirmed the executable path and package version, and nothing has been changed yet.
2. Make a recoverable copy
Pick the file to convert, replace /path/to/client-prog.c with the real path, then make a separate original alongside it:
$ cp -- /path/to/client-prog.c /path/to/client-prog.c.orig
$ cmp -- /path/to/client-prog.c /path/to/client-prog.c.orig
A successful cmp prints nothing and returns status 0. If it reports a difference, stop and work out which file is the trusted original before continuing.
Warning
The next command edits the working source in place. Do not run it against the only copy of a valuable program. If conversion goes wrong, restore the backup with:
$ cp -- /path/to/client-prog.c.orig /path/to/client-prog.c
That overwrites the converted working file, so check both paths carefully before pressing Enter.
3. Convert the source file
Run the command with the source path as its operand:
$ msql2mysql /path/to/client-prog.c
/path/to/client-prog.c converted
- Skip
--. This installed command passes its operands straight to the underlying replacement utility, and a literal--gets treated as a file name rather than a documented option separator. - The message names the file that changed. The utility converts mSQL C API calls to their MySQL equivalents and rewrites the mSQL header name too. On this MariaDB 10.11 install, a small test containing
msql_query,msqlFetchRowandmsqlStoreResultcame out asmysql_query,mysql_fetch_rowandmysql_store_result, withm_resultchanged toMYSQL_RES. - Several files can be given at once. The documented synopsis accepts one or more C source files, but each named file still gets changed in place, so back up every one of them.
$ cp -- client-a.c client-a.c.orig
$ cp -- client-b.c client-b.c.orig
$ msql2mysql client-a.c client-b.c
client-a.c converted
client-b.c converted
4. Review the rewrite before compiling
A conversion message is not proof the program is ready. Diff the converted file against its backup:
$ diff -u -- client-prog.c.orig client-prog.c
--- client-prog.c.orig
+++ client-prog.c
@@
-#include <msql.h>
+#include <mysql.h>
@@
- msqlFetchRow(result);
+ mysql_fetch_row(result);
Your diff will differ. Look for calls whose surrounding logic needs more than a name change: result handling, connection setup, error handling, header or library choices. The utility performs substitutions; it does not understand your program's control flow, and it does not prove the two APIs behave identically for every call.
Checkpoint
The diff contains only changes you understand, and the original file is still sitting at client-prog.c.orig.
5. Compile or run the project's checks
Use the project's normal build command after reviewing the diff. A generic example, only useful once the paths match your installation:
$ cc -Wall -Wextra -I/path/to/mysql/include -c client-prog.c -o client-prog.o
Do not copy that command unchanged unless those paths are real and the source is otherwise ready to compile. A compiler error is useful feedback about remaining API or build changes, not a reason to go and edit the backup.
6. Recover or repeat safely
If review or the build shows the rewrite is unsuitable, restore the original and verify it:
$ cp -- client-prog.c.orig client-prog.c
$ cmp -- client-prog.c client-prog.c.orig
To try again, make a fresh backup of the restored source before running msql2mysql once more. Do not use a converted file as the only input for repeated experiments: the substitutions are not a substitute for source control or a clean baseline.
Tip
For a cleaner workflow, do the conversion in a temporary working tree or a new branch, review the diff there, and copy only the reviewed changes into the real project. No elevated privileges are required unless your source directory itself is protected; if a command asks for sudo merely because conversion failed, stop and check the file path and permissions first.
Done means
- Version confirmed. The installed
msql2mysqlpath andmariadb-clientversion are known. - Every file backed up. Each source file passed to the command has a separate original copy.
- Change verified. The conversion message and a file diff confirm what actually changed.
- Build checked. The converted code has passed the project's compiler or test checks.
- Recovery understood. You know how to restore the original without touching unrelated files.