Before starting: Make sure you have the necessary folders and permissions — get more information.

Links: Homepage | Downloads | Reference Manual
Dependencies: CMake
Version: 5.7.14

MySQL is an open-source relational database management server (RDBMS).

Get the Code

Switch to /usr/local/src and download the source package.

cd /usr/local/src
curl --remote-name --location

Extract the archive and move into the folder.

tar -xzvf mysql-VERSION.tar.gz
cd mysql-VERSION

Compile and Install

Configure, compile and install into /usr/local/mysql-VERSION.

cmake \
  -DCMAKE_CXX_FLAGS="-stdlib=libstdc++" \
  -DDEFAULT_COLLATION=utf8_general_ci \
  -DWITH_BOOST=/usr/local/src/boost \
make install

Create a symbolic link that points /usr/local/mysql to /usr/local/mysql-VERSION.

ln -s mysql-VERSION /usr/local/mysql


Execute the following lines to update your Bash startup script.

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
echo 'export MANPATH=/usr/local/mysql/man:$MANPATH' >> ~/.bash_profile

Load the new shell configurations.

source ~/.bash_profile


Create a folder that will contain your databases. My databases are located in /usr/local/var/mysql. You can place your databases wherever you'd like but make sure you update the path when mentioned throughout this article.

mkdir -p /usr/local/var/mysql


Perform either the upgrade or new installation steps below depending on your situation.


Upgrade your database server after the installation. Must start server first (see below).

mysql_upgrade -u root -p

New Installation

Initialize your database server.

mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/var/mysql

The password from the previous command is temporary. Launch the MySQL client and enter the temporary password. Must start server first (see below).

mysql -u root -p

After connecting, assign a new root password.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Manual Start/Stop

To start the MySQL server.

mysqld_safe --datadir=/usr/local/var/mysql --log-error=/usr/local/var/log/mysql.log &

To shut down the MySQL server.

mysqladmin --user=root --password shutdown

Automatically Start the Server at Boot

Create a configuration file for Launchd.

nano ~/Library/LaunchAgents/com.mysql.mysqld.plist

Copy and paste the following text into the aforementioned file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">




Register with Launchd and start the server.

launchctl load ~/Library/LaunchAgents/com.mysql.mysqld.plist

Deregister with Launchd.

launchctl unload ~/Library/LaunchAgents/com.mysql.mysqld.plist

Verify the Installation

Verify that you have successfully installed MySQL.

mysqld --version

Log into the database using the MySQL client.

mysql --user=root --password