MARIADB
MySQL
SQL

The Process of Compiling MySQL from Source

intro

For many, the process of compiling MySQL is the source of headaches. It doesn’t have to be that way — read this blog and you will understand that building MySQL from source isn’t that hard after all!

Tools used in the tutorial
Tool Description Link

There are various ways to use MySQL. For many of us, methods to install and use MySQL vary from the operating system(s) in question — most of the development environments for programmers will be Linux-based while many demo environments will be based on Windows. However, before we even consider our MySQL instances to be usable, our database instances must be installed and set up properly. Here’s how to compile MySQL from source static!

Why Compile MySQL from the Source?

Developers have multiple ways to use MySQL and related database management systems but those that opt to compile MySQL from source static do so because of one or more of the following reasons:

  1. Building a database management system like MySQL from source allows developers to heavily customize build parameters or libraries.
  2. The installation location, compiler parameters, and various libraries can be tweaked.

Of course, everything’s done within limits and MySQL is indeed very vocal about those — at the same time, for those that compile MySQL from the source code, MySQL does provide everyone with an INFO_BIN file that contains information about how MySQL is to be configured, compiled, and/or distributed.

How to Compile MySQL from the Source?

So, how exactly do you compile MySQL from source static code? MySQL notes that there are two ways to accomplish this task. We can do this by either:

  1. Downloading a MySQL source distribution.

In other words, we can either configure, build, and install MySQL by downloading it as a source distribution, unzipping it and installing it on our PC or clone a git repository and compile MySQL from source static that way. Here’s how everything looks like.

Installing MySQL Using a Standard MySQL Source Distribution

To install MySQL in the “vanilla” way, we first need to verify that our system(s) in question conform with the prerequisites outlined by MySQL themselves. We can do that by checking out the prerequisites in the documentation that may change as MySQL evolves, however, the standard minimum requirements are as follows:

  • Support for a recent version of C++ (17 as of the time this blog is being written.)
  • Windows 10 or later if Windows is in use.
  • Support for SSL libraries to support encrypted connections and the like.
  • Free memory on our server (MySQL doesn’t specify how much — aim for at least 30%)
  • Support for the ncurses library.

Once that’s done, we need to setup a mysql user — this user will own database directories and will be used to run MySQL Server in and of itself. Then, unzip the MySQL distribution you have on file and fiddle with its configuration:

Step 1: Install the necessary dependencies for MySQL.

Step 2: Configure the MySQL Server build by using cmake and specifying your options after creating a directory:

Copy
        
1 mkdir build # creating a build directory 2 cd build # navigating into the directory 3 cmake .. [your_options] # configuring the MySQL Server build

Step 3: Compile MySQL Server by using a make command, then install MySQL by issuing sudo make install.

Step 4: Verify that MySQL Server has been installed by running /path/to/mysqld --version (replace /path/to/mysqld with the path towards the MySQL daemon.)

Step 5: Configure MySQL. Setup the mysql user, the base directory, and the data directory as well: sudo /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

Step 6: Start MySQL Server “on a loop” by issuing something akin to sudo /path/to/mysqld_safe --user=mysql & (replate the /path/to/mysqld_safe with the actual path and don’t forget the & at the end — it makes MySQL be able to be up and running without you re-running the command.)

Step 7: Perform post-installation setup and testing if necessary — in many cases, this will involve fiddling with the my.cnf or my.ini file, creating databases, tables, indexes, and partitions within them, and other things.

Installing MySQL Using a Development Source Tree

To install MySQL using a development source tree, first clone MySQL onto your server:

  1. Issue a git clone command. Something like git clone https://github.com/mysql/mysql-server.git should do.
  2. Once MySQL is cloned, navigate into the mysql-server directory and check out the folders and files to ensure everything’s in place.
  3. If you want to view the remote tracking branches using git, issue a git branch -r command.
  4. To check out a branch of MySQL Server, use git checkout [version]: something like git checkout 8.4 should do.
  5. Follow the steps in the Installing MySQL Using a Standard MySQL Source Distribution heading after skipping the downloading and unzipping MySQL Server part.

Things to Note

The compile MySQL from source static process may seem a little daunting, and that’s why you need to understand why you do the things you do:

  1. You create a build directory in order to automate the MySQL “building” process.
  2. You can run cmake with options like -WITH_SSL=... -WITH_ZLIB=... -DSTATIC_LINKING=[0|1] and others to build MySQL Server over TLS, make it support the ZLib data compression algorithm, and many other things. It is not necessary to run it with default settings.
  3. Starting MySQL with the & sign or “on a loop” is important because otherwise, you will need to re-do this step every time you restart your server.
  4. Don’t forget to configure MySQL Server once it’s installed — fiddle with the parameters in my.cnf and if necessary, restore the options within them from a backup.

Summary

The compile MySQL from source static process may seem daunting at first, but once you understand the intricacies behind it, everything falls into their own places. We hope that this blog has helped you understand why certain steps in the compiling process are necessary and we hope to see you around in some of our upcoming blogs. For now, make sure to follow our blog through TheTable, and until next time.

FAQ

What does compile MySQL from source static method refer to?

The compile MySQL from source static method refers to developers building MySQL “from the ground up” and modifying the parameters or libraries in the process.

Where can I learn more about MySQL and other DBMS?

To learn more about MySQL and other database management systems, read the documentation, blogs, books on MySQL, and don’t forget to attend conferences to network with professionals in your field. Reading books like “Hacking MySQL: Breaking, Optimizing, and Securing MySQL for Your Use Case” will be a good place to start and reading blogs like TheTable will also be a great place if you want to expand your existing knowledge.

Why should I use DbVisualizer Pro?

Consider using the Pro version of DbVisualizer because the Pro version of DbVisualizer will allow you to export data in various formats, edit data as if it were a spreadsheet, view XML data in a tree or text formats, it will come with an SQL formatter with extensive customization options, and provide you with various other ways to solve database-related issues and problems. Try DbVisualizer Pro today!

Dbvis download link img
About the author
LukasVileikisPhoto
Lukas Vileikis
Lukas Vileikis is an ethical hacker and a frequent conference speaker. He runs one of the biggest & fastest data breach search engines in the world - BreachDirectory.com, frequently speaks at conferences and blogs in multiple places including his blog over at lukasvileikis.com.
The Table Icon
Sign up to receive The Table's roundup
More from the table
Title Author Tags Length Published
title

SQL Boolean Type: How to Use It in All Major Relational Databases

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 8 min 2025-09-23
title

How Dirty Data Pollutes Your Database

author Lukas Vileikis tags SQL 5 min 2025-09-22
title

Best Database Tools for Developers: Ultimate List

author Antonello Zanini tags Developer tools SQL 9 min 2025-09-17
title

Implementing Version Control for Your Database

author Lukas Vileikis tags SQL 4 min 2025-09-16
title

JSON_EXTRACT MySQL Function: Complete Guide

author Antonello Zanini tags MySQL 6 min 2025-09-10
title

What Happens When You Use the UNION and DISTINCT SQL Clauses Together?

author Lukas Vileikis tags SQL 5 min 2025-09-08
title

OpenSearch vs Elasticsearch: Is OpenSeach an Open-Source Alternative to ElasticSearch?

author Lukas Vileikis tags DbVisualizer ELASTICSEARCH NOSQL SQL 4 min 2025-08-26
title

Understanding MySQL Data Types: A Complete Guide for Beginners

author Lukas Vileikis tags DATA TYPES MARIADB MySQL 6 min 2025-08-20
title

SQL IS NOT NULL Condition: Definitive Guide

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 6 min 2025-08-13
title

Can a Primary Key Be NULL in an SQL Table?

author TheTable tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 5 min 2025-08-12

The content provided on dbvis.com/thetable, including but not limited to code and examples, is intended for educational and informational purposes only. We do not make any warranties or representations of any kind. Read more here.