How to Install mysql-dev for Server on Ubuntu

22.04aptcMySQL

I am working on a server plugin for MySQL v8.0 (as well as a legacy plugin for v5.7) and I need to install the correct header files. I've looked around the internet and all I can find is libmysqlclient-dev, which is for client dev. I need to install a server development package so I can include headers such as mysql/plugin_auth.h.

Can this be done?

Best Answer

The default repositories in Ubuntu don't include the server development package for MySQL by default, but you can work around this limitation by installing the MySQL source code.

Open the terminal and type:

sudo apt update
sudo apt install build-essential libncurses-dev libssl-dev zlib1g-dev cmake git libboost-all-dev pkg-config bison 
git clone https://github.com/mysql/mysql-server.git

This will download the MySQL source code. You can then navigate to the directory in which you downloaded the MySQL source code, and compile the server which will install the necessary header files in the standard include directories.

In order for CMake to work, the author also had to install libboost-all-dev and pkg-config. Additionally, after cloning the repository, the author had to install bison and run cd <repo>/sql/ then bison sql_yacc.yy -o sql_yacc.cc -Hsql_yacc.hh and bison sql_hints.yy -o sql_hints.yy.cc -Hsql_hints.yy.hh Thanks to Cardinal System for commenting.

MySQL 5.7 reached its end of life in October 2023. This means it will no longer receive official security updates or bug fixes. You can install MySQL 5.7 on Ubuntu 22.04 by following the steps in How to Install MySQL 5.7 on Ubuntu 18.04, 20.04, or later.

You must compile plugins with the entire server source code present, not just the libraries and header files. (source)