One issue that developers often run into is needing or wanting to run a development version of MariaDB or MySQL on their desktop when there is already a production version installed. You may want to try out a new feature, or experiment with a patch, or maybe you’re developing a new storage engine, or just having fun hacking on the code. Whatever the reason, when this happens to me I often want to be able to run the non-standard version without replacing my currently installed version.
Fortunately, the process for doing so is easy. The instructions below are adapted from the Running MariaDB from the source directory article in the AskMonty Knowledgebase.
Before beginning, make sure you shut down your running instance of mysqld before starting your test instance. It is possible to run multiple mysqlds on the same server, but doing so is beyond the scope of this blog post.
With that out of the way, the first step is to download and compile the source code. There are howtos on this for various operating systems and Linux distributions on the AskMonty Knowledgebase.
Follow the compilation instructions up to the point where you would normally do make install and stop before you do that. Instead create a .my.cnf file (notice the leading ‘.’) in your home directory (i.e. ‘~/.my.cnf‘). Start with the example one given in the above Knowledgebase article.
There are two lines in the example file which you must edit if you want things to work: the ‘data=’ line and the ‘language=’ line. These two lines must contain hard-coded paths to your test data directory (if you’re testing, you should not set it to your ‘real’ data directory) and the language files.
Once you have your customized .my.cnf file in place, cd over to the source directory and run the following command:
./scripts/mysql_install_db --srcdir=$PWD --datadir=/path/to/data/dir
‘$PWD’ in the command above is the environment variable which points to your current directory. On some systems you may need to replace it with the path manually. Also, the ‘–datadir’ variable isn’t strictly needed if you added it to your ~/.my.cnf file. What the above command does is create the base mysql schema that mysqld needs in order to run.
Now, assuming you compiled MySQL or MariaDB correctly, you can start mysqld with:
cd sql ./mysqld &
You may want to start the server inside the debugger (especially if you are doing development work):
cd sql ddd mysqld &
Pay attention to any errors as the server daemon starts up. Assuming you compiled thing successfully, an error at this stage often means your ‘~/.my.cnf’ file has a typo or other error in it.
After successfully starting up mysqld using one of the above methods (with the debugger or without), launch the mysql client (as root if you don’t have any users setup yet).
If you successfully connect, congratulations! You’re running mysqld from the source directory without installing it!
What about Windows?
The above instructions are for Linux and Unix-like systems. But you can do the same thing on Windows with some alterations. See the AskMonty Knowledgebase article for details.